Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/api/repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { repos } from "@openally/github.sdk";
// Collect all tags
const tags = await repos.OpenAlly["github.sdk"].tags();

// Collect all contributors
const contributors = await repos.OpenAlly["github.sdk"].contributors();

// Stream pull requests page by page
for await (const pr of repos.nodejs.node.pulls()) {
console.log(pr.number, pr.title);
Expand Down Expand Up @@ -64,6 +67,14 @@ Lists commits.

> GitHub docs: [List commits](https://docs.github.com/en/rest/commits/commits#list-commits)

### `.contributors()`

Returns `ApiEndpoint<Contributor>`.

Lists contributors to the repository, sorted by number of commits.

> GitHub docs: [List repository contributors](https://docs.github.com/en/rest/repos/repos#list-repository-contributors)

### `.workflows()`

Returns `ApiEndpoint<Workflow>`.
Expand Down
3 changes: 3 additions & 0 deletions src/api/repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
PullRequest,
Issue,
Commit,
Contributor,
Workflow,
WorkflowRun,
Job,
Expand All @@ -22,6 +23,7 @@ type RepoEndpointMethods = {
pulls: () => ApiEndpoint<PullRequest>;
issues: () => ApiEndpoint<Issue>;
commits: () => ApiEndpoint<Commit>;
contributors: () => ApiEndpoint<Contributor>;
workflows: () => ApiEndpoint<Workflow>;
workflowRuns: (workflowId: string | number) => ApiEndpoint<WorkflowRun>;
runJobs: (runId: number) => ApiEndpoint<Job>;
Expand All @@ -44,6 +46,7 @@ function createRepoProxy(
pulls: () => new ApiEndpoint<PullRequest>(`/repos/${owner}/${repo}/pulls`, config),
issues: () => new ApiEndpoint<Issue>(`/repos/${owner}/${repo}/issues`, config),
commits: () => new ApiEndpoint<Commit>(`/repos/${owner}/${repo}/commits`, config),
contributors: () => new ApiEndpoint<Contributor>(`/repos/${owner}/${repo}/contributors`, config),
workflows: () => new ApiEndpoint<Workflow>(
`/repos/${owner}/${repo}/actions/workflows`,
{
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type Tag = Endpoints["GET /repos/{owner}/{repo}/tags"]["response"]["data"
export type PullRequest = Endpoints["GET /repos/{owner}/{repo}/pulls"]["response"]["data"][number];
export type Issue = Endpoints["GET /repos/{owner}/{repo}/issues"]["response"]["data"][number];
export type Commit = Endpoints["GET /repos/{owner}/{repo}/commits"]["response"]["data"][number];
export type Contributor = Endpoints["GET /repos/{owner}/{repo}/contributors"]["response"]["data"][number];
export type Workflow = Endpoints["GET /repos/{owner}/{repo}/actions/workflows"]["response"]["data"]["workflows"][number];
export type WorkflowRun = Endpoints[
"GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs"
Expand Down
14 changes: 14 additions & 0 deletions test/repos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("Repos API", () => {
assert.ok(methods.pulls() instanceof ApiEndpoint);
assert.ok(methods.issues() instanceof ApiEndpoint);
assert.ok(methods.commits() instanceof ApiEndpoint);
assert.ok(methods.contributors() instanceof ApiEndpoint);
assert.ok(methods.workflows() instanceof ApiEndpoint);
});

Expand Down Expand Up @@ -128,6 +129,19 @@ describe("Repos API", () => {
assert.deepEqual(result, [{ number: 5, title: "Bug report" }]);
});

it("should fetch contributors for a repo", async() => {
mockAgent
.get(kGithubOrigin)
.intercept({ path: "/repos/octocat/hello-world/contributors", method: "GET" })
.reply(200, JSON.stringify([{ login: "octocat", contributions: 42 }]), {
headers: { "content-type": "application/json" }
});

const result = await repos.octocat["hello-world"].contributors().all();

assert.deepEqual(result, [{ login: "octocat", contributions: 42 }]);
});

it("should fetch commits for a repo", async() => {
mockAgent
.get(kGithubOrigin)
Expand Down
Loading