@openally/github.sdk 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +5 -4
  3. package/dist/api/rawFile.d.ts +20 -0
  4. package/dist/api/rawFile.d.ts.map +1 -0
  5. package/dist/api/rawFile.js +25 -0
  6. package/dist/api/rawFile.js.map +1 -0
  7. package/dist/api/repos.d.ts +21 -0
  8. package/dist/api/repos.d.ts.map +1 -0
  9. package/dist/api/repos.js +32 -0
  10. package/dist/api/repos.js.map +1 -0
  11. package/dist/api/users.d.ts +21 -0
  12. package/dist/api/users.d.ts.map +1 -0
  13. package/dist/api/users.js +20 -0
  14. package/dist/api/users.js.map +1 -0
  15. package/dist/class/ApiEndpoint.d.ts +20 -0
  16. package/dist/class/ApiEndpoint.d.ts.map +1 -0
  17. package/dist/class/ApiEndpoint.js +60 -0
  18. package/dist/class/ApiEndpoint.js.map +1 -0
  19. package/dist/class/GithubClient.d.ts +22 -0
  20. package/dist/class/GithubClient.d.ts.map +1 -0
  21. package/dist/class/GithubClient.js +21 -0
  22. package/dist/class/GithubClient.js.map +1 -0
  23. package/dist/class/HttpLinkParser.d.ts +4 -0
  24. package/dist/class/HttpLinkParser.d.ts.map +1 -0
  25. package/dist/class/HttpLinkParser.js +14 -0
  26. package/dist/class/HttpLinkParser.js.map +1 -0
  27. package/dist/class/createApiProxy.d.ts +2 -0
  28. package/dist/class/createApiProxy.d.ts.map +1 -0
  29. package/dist/class/createApiProxy.js +8 -0
  30. package/dist/class/createApiProxy.js.map +1 -0
  31. package/dist/constants.d.ts +4 -0
  32. package/dist/constants.d.ts.map +1 -0
  33. package/dist/constants.js +4 -0
  34. package/dist/constants.js.map +1 -0
  35. package/{src/index.ts → dist/index.d.ts} +2 -1
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +5 -0
  38. package/dist/index.js.map +1 -0
  39. package/{src/types.ts → dist/types.d.ts} +14 -19
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +2 -0
  42. package/dist/types.js.map +1 -0
  43. package/package.json +6 -3
  44. package/.all-contributorsrc +0 -16
  45. package/.editorconfig +0 -14
  46. package/.github/dependabot.yml +0 -25
  47. package/.github/workflows/codeql.yml +0 -78
  48. package/.github/workflows/node.js.yml +0 -52
  49. package/.github/workflows/publish.yml +0 -29
  50. package/.github/workflows/scorecards.yml +0 -76
  51. package/SECURITY.md +0 -5
  52. package/docs/api/ApiEndpoint.md +0 -37
  53. package/docs/api/GithubClient.md +0 -50
  54. package/docs/api/repos.md +0 -97
  55. package/docs/api/users.md +0 -76
  56. package/eslint.config.mjs +0 -3
  57. package/src/api/repos.ts +0 -74
  58. package/src/api/users.ts +0 -47
  59. package/src/class/ApiEndpoint.ts +0 -105
  60. package/src/class/GithubClient.ts +0 -31
  61. package/src/class/HttpLinkParser.ts +0 -17
  62. package/src/class/createApiProxy.ts +0 -9
  63. package/test/ApiEndpoint.spec.ts +0 -301
  64. package/test/GithubClient.spec.ts +0 -166
  65. package/test/HttpLinkParser.spec.ts +0 -78
  66. package/test/createApiProxy.spec.ts +0 -58
  67. package/test/repos.spec.ts +0 -221
  68. package/test/users.spec.ts +0 -159
  69. package/tsconfig.json +0 -11
package/.editorconfig DELETED
@@ -1,14 +0,0 @@
1
- # Editor configuration, see https://editorconfig.org
2
- root = true
3
-
4
- [*]
5
- charset = utf-8
6
- indent_style = space
7
- indent_size = 2
8
- insert_final_newline = true
9
- trim_trailing_whitespace = true
10
- end_of_line = lf
11
-
12
- [*.md]
13
- max_line_length = off
14
- trim_trailing_whitespace = false
@@ -1,25 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: github-actions
4
- directory: /
5
- schedule:
6
- interval: monthly
7
- cooldown:
8
- default-days: 5
9
- groups:
10
- github-actions:
11
- patterns:
12
- - "*"
13
-
14
- - package-ecosystem: npm
15
- directory: /
16
- versioning-strategy: widen
17
- schedule:
18
- interval: weekly
19
- cooldown:
20
- default-days: 5
21
- groups:
22
- dependencies:
23
- dependency-type: "production"
24
- development-dependencies:
25
- dependency-type: "development"
@@ -1,78 +0,0 @@
1
- # For most projects, this workflow file will not need changing; you simply need
2
- # to commit it to your repository.
3
- #
4
- # You may wish to alter this file to override the set of languages analyzed,
5
- # or to provide custom queries or build logic.
6
- #
7
- # ******** NOTE ********
8
- # We have attempted to detect the languages in your repository. Please check
9
- # the `language` matrix defined below to confirm you have the correct set of
10
- # supported CodeQL languages.
11
- #
12
- name: "CodeQL"
13
-
14
- on:
15
- push:
16
- branches: ["main"]
17
- pull_request:
18
- # The branches below must be a subset of the branches above
19
- branches: ["main"]
20
- schedule:
21
- - cron: "0 0 * * 1"
22
-
23
- permissions:
24
- contents: read
25
-
26
- jobs:
27
- analyze:
28
- name: Analyze
29
- runs-on: ubuntu-latest
30
- permissions:
31
- actions: read
32
- contents: read
33
- security-events: write
34
-
35
- strategy:
36
- fail-fast: false
37
- matrix:
38
- language: ["typescript"]
39
- # CodeQL supports [ $supported-codeql-languages ]
40
- # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
41
-
42
- steps:
43
- - name: Harden Runner
44
- uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1
45
- with:
46
- egress-policy: audit
47
-
48
- - name: Checkout repository
49
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
50
-
51
- # Initializes the CodeQL tools for scanning.
52
- - name: Initialize CodeQL
53
- uses: github/codeql-action/init@89a39a4e59826350b863aa6b6252a07ad50cf83e # v4.32.4
54
- with:
55
- languages: ${{ matrix.language }}
56
- # If you wish to specify custom queries, you can do so here or in a config file.
57
- # By default, queries listed here will override any specified in a config file.
58
- # Prefix the list here with "+" to use these queries and those in the config file.
59
-
60
- # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
61
- # If this step fails, then you should remove it and run the build manually (see below)
62
- - name: Autobuild
63
- uses: github/codeql-action/autobuild@89a39a4e59826350b863aa6b6252a07ad50cf83e # v4.32.4
64
-
65
- # ℹ️ Command-line programs to run using the OS shell.
66
- # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
67
-
68
- # If the Autobuild fails above, remove it and uncomment the following three lines.
69
- # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
70
-
71
- # - run: |
72
- # echo "Run, Build Application using script"
73
- # ./location_of_script_within_repo/buildscript.sh
74
-
75
- - name: Perform CodeQL Analysis
76
- uses: github/codeql-action/analyze@89a39a4e59826350b863aa6b6252a07ad50cf83e # v4.32.4
77
- with:
78
- category: "/language:${{matrix.language}}"
@@ -1,52 +0,0 @@
1
- # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
- # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
-
4
- name: Node.js CI
5
-
6
- on:
7
- push:
8
- branches: [ "main" ]
9
- pull_request:
10
- branches: [ "main" ]
11
-
12
- permissions:
13
- contents: read
14
-
15
- jobs:
16
- build:
17
-
18
- runs-on: ubuntu-latest
19
-
20
- strategy:
21
- matrix:
22
- node-version: [24.x]
23
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
24
-
25
- steps:
26
- - name: Harden Runner
27
- uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1
28
- with:
29
- egress-policy: audit
30
-
31
- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
32
- - name: Use Node.js ${{ matrix.node-version }}
33
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
34
- with:
35
- node-version: ${{ matrix.node-version }}
36
- - run: npm install --ignore-scripts
37
- - run: npm run build --if-present
38
- - run: npm test
39
- automerge:
40
- if: >
41
- github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]'
42
- needs:
43
- - build
44
- runs-on: ubuntu-latest
45
- permissions:
46
- contents: write
47
- pull-requests: write
48
- steps:
49
- - name: Merge Dependabot PR
50
- uses: fastify/github-action-merge-dependabot@1b2ed42db8f9d81a46bac83adedfc03eb5149dff # v3.11.2
51
- with:
52
- github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -1,29 +0,0 @@
1
- name: Publish Package
2
-
3
- on:
4
- push:
5
- tags:
6
- - 'v*'
7
-
8
- permissions:
9
- id-token: write # Required for OIDC
10
- contents: read
11
-
12
- jobs:
13
- publish:
14
- runs-on: ubuntu-latest
15
- steps:
16
- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17
-
18
- - uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
19
- with:
20
- node-version: '24.x'
21
- registry-url: 'https://registry.npmjs.org'
22
-
23
- # Ensure npm 11.5.1 or later is installed
24
- - name: Update npm
25
- run: npm install -g npm@latest
26
- - run: npm install --ignore-scripts
27
- - run: npm run build --if-present
28
- - run: npm test
29
- - run: npm publish
@@ -1,76 +0,0 @@
1
- # This workflow uses actions that are not certified by GitHub. They are provided
2
- # by a third-party and are governed by separate terms of service, privacy
3
- # policy, and support documentation.
4
-
5
- name: Scorecard supply-chain security
6
- on:
7
- # For Branch-Protection check. Only the default branch is supported. See
8
- # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
9
- branch_protection_rule:
10
- # To guarantee Maintained check is occasionally updated. See
11
- # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
12
- schedule:
13
- - cron: '20 7 * * 2'
14
- push:
15
- branches: ["main"]
16
-
17
- # Declare default permissions as read only.
18
- permissions: read-all
19
-
20
- jobs:
21
- analysis:
22
- name: Scorecard analysis
23
- runs-on: ubuntu-latest
24
- permissions:
25
- # Needed to upload the results to code-scanning dashboard.
26
- security-events: write
27
- # Needed to publish results and get a badge (see publish_results below).
28
- id-token: write
29
- contents: read
30
- actions: read
31
-
32
- steps:
33
- - name: Harden Runner
34
- uses: step-security/harden-runner@e3f713f2d8f53843e71c69a996d56f51aa9adfb9 # v2.14.1
35
- with:
36
- egress-policy: audit
37
-
38
- - name: "Checkout code"
39
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
40
- with:
41
- persist-credentials: false
42
-
43
- - name: "Run analysis"
44
- uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
45
- with:
46
- results_file: results.sarif
47
- results_format: sarif
48
- # (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
49
- # - you want to enable the Branch-Protection check on a *public* repository, or
50
- # - you are installing Scorecards on a *private* repository
51
- # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
52
- # repo_token: ${{ secrets.SCORECARD_TOKEN }}
53
-
54
- # Public repositories:
55
- # - Publish results to OpenSSF REST API for easy access by consumers
56
- # - Allows the repository to include the Scorecard badge.
57
- # - See https://github.com/ossf/scorecard-action#publishing-results.
58
- # For private repositories:
59
- # - `publish_results` will always be set to `false`, regardless
60
- # of the value entered here.
61
- publish_results: true
62
-
63
- # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
64
- # format to the repository Actions tab.
65
- - name: "Upload artifact"
66
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
67
- with:
68
- name: SARIF file
69
- path: results.sarif
70
- retention-days: 5
71
-
72
- # Upload the results to GitHub's code scanning dashboard.
73
- - name: "Upload to code-scanning"
74
- uses: github/codeql-action/upload-sarif@89a39a4e59826350b863aa6b6252a07ad50cf83e # v4.32.4
75
- with:
76
- sarif_file: results.sarif
package/SECURITY.md DELETED
@@ -1,5 +0,0 @@
1
- # Reporting Security Issues
2
-
3
- To report a security issue, please [publish a private security advisory](https://github.com/OpenAlly/github.sdk/security/advisories) with a description of the issue, the steps you took to create the issue, affected versions, and, if known, mitigations for the issue.
4
-
5
- Our vulnerability management team will respond within one week. If the issue is confirmed as a vulnerability, we will open a Security Advisory and acknowledge your contributions as part of it. This project follows a 90 day disclosure timeline.
@@ -1,37 +0,0 @@
1
- # ApiEndpoint
2
-
3
- Every endpoint method returns an `ApiEndpoint<T>` instance. It transparently handles pagination, authentication, and data extraction.
4
-
5
- ```ts
6
- import { repos } from "@openally/github.sdk";
7
-
8
- const endpoint = repos.nodejs.node.pulls()
9
- .setBearerToken(process.env.GITHUB_TOKEN)
10
- .setAgent("my-app/1.0.0");
11
-
12
- // Stream items one by one across all pages
13
- for await (const pr of endpoint.iterate()) {
14
- console.log(pr.title);
15
- }
16
-
17
- // Or collect everything at once
18
- const allPRs = await endpoint.all();
19
- ```
20
-
21
- ## Methods
22
-
23
- ### `.setBearerToken(token: string): this`
24
-
25
- Attaches a GitHub personal access token as a `Bearer` authorization header. Returns the instance for chaining.
26
-
27
- ### `.setAgent(userAgent: string): this`
28
-
29
- Overrides the `User-Agent` request header. Returns the instance for chaining.
30
-
31
- ### `.iterate(): AsyncIterableIterator<T>`
32
-
33
- Asynchronously iterates over all items across all pages. Pagination is handled transparently via GitHub's `Link` response header — you never need to manage page numbers or cursors manually.
34
-
35
- ### `.all(): Promise<T[]>`
36
-
37
- Collects all pages and resolves with a flat array of every item.
@@ -1,50 +0,0 @@
1
- # GithubClient
2
-
3
- `GithubClient` is the recommended entry point when you need a shared token or `User-Agent` applied to every request without configuring each endpoint individually.
4
-
5
- ```ts
6
- import { GithubClient } from "@openally/github.sdk";
7
-
8
- const github = new GithubClient({
9
- token: process.env.GITHUB_TOKEN,
10
- userAgent: "my-app/1.0.0"
11
- });
12
-
13
- // Iterate over all open pull requests
14
- for await (const pr of github.repos.OpenAlly["github.sdk"].pulls().iterate()) {
15
- console.log(pr.title);
16
- }
17
-
18
- // Collect all tags at once
19
- const tags = await github.repos.OpenAlly["github.sdk"].tags().all();
20
-
21
- // List all repositories for a user
22
- const userRepos = await github.users.torvalds.repos().all();
23
- ```
24
-
25
- ## Constructor
26
-
27
- ```ts
28
- new GithubClient(options?: GithubClientOptions)
29
- ```
30
-
31
- ```ts
32
- interface GithubClientOptions {
33
- /**
34
- * GitHub personal access token sent as a Bearer authorization header.
35
- * Required for private resources and to increase the API rate limit.
36
- */
37
- token?: string;
38
-
39
- /**
40
- * Value for the User-Agent request header.
41
- * @default "@openally/github.sdk/1.0.0"
42
- */
43
- userAgent?: string;
44
- }
45
- ```
46
-
47
- ## Properties
48
-
49
- - **`repos`** — `ReposProxy` — see [repos](./repos.md)
50
- - **`users`** — `UsersProxy` — see [users](./users.md)
package/docs/api/repos.md DELETED
@@ -1,97 +0,0 @@
1
- # repos
2
-
3
- The `repos` proxy provides access to GitHub repository endpoints.
4
-
5
- ```ts
6
- import { repos } from "@openally/github.sdk";
7
-
8
- // Collect all tags
9
- const tags = await repos.OpenAlly["github.sdk"].tags().all();
10
-
11
- // Stream pull requests page by page
12
- for await (const pr of repos.nodejs.node.pulls().iterate()) {
13
- console.log(pr.number, pr.title);
14
- }
15
-
16
- // Stream workflow runs for a specific workflow file
17
- for await (const run of repos.nodejs.node.workflowRuns("ci.yml").iterate()) {
18
- console.log(run.id, run.status);
19
- }
20
-
21
- // Collect all jobs for a specific run
22
- const jobs = await repos.nodejs.node.runJobs(12345678).all();
23
- ```
24
-
25
- ## Access pattern
26
-
27
- ```ts
28
- repos[owner][repo].<method>()
29
- ```
30
-
31
- All methods return an [`ApiEndpoint<T>`](./ApiEndpoint.md) instance.
32
-
33
- ## Methods
34
-
35
- ### `.tags()`
36
-
37
- Returns `ApiEndpoint<Tag>`.
38
-
39
- Lists all tags for the repository.
40
-
41
- > GitHub docs: [List repository tags](https://docs.github.com/en/rest/repos/repos#list-repository-tags)
42
-
43
- ### `.pulls()`
44
-
45
- Returns `ApiEndpoint<PullRequest>`.
46
-
47
- Lists pull requests.
48
-
49
- > GitHub docs: [List pull requests](https://docs.github.com/en/rest/pulls/pulls#list-pull-requests)
50
-
51
- ### `.issues()`
52
-
53
- Returns `ApiEndpoint<Issue>`.
54
-
55
- Lists repository issues.
56
-
57
- > GitHub docs: [List repository issues](https://docs.github.com/en/rest/issues/issues#list-repository-issues)
58
-
59
- ### `.commits()`
60
-
61
- Returns `ApiEndpoint<Commit>`.
62
-
63
- Lists commits.
64
-
65
- > GitHub docs: [List commits](https://docs.github.com/en/rest/commits/commits#list-commits)
66
-
67
- ### `.workflows()`
68
-
69
- Returns `ApiEndpoint<Workflow>`.
70
-
71
- Lists all GitHub Actions workflows defined in the repository.
72
-
73
- > GitHub docs: [List repository workflows](https://docs.github.com/en/rest/actions/workflows#list-repository-workflows)
74
-
75
- ### `.workflowRuns(workflowId: string | number)`
76
-
77
- Returns `ApiEndpoint<WorkflowRun>`.
78
-
79
- Lists runs for a specific workflow, identified by filename (e.g. `"ci.yml"`) or numeric ID.
80
-
81
- > GitHub docs: [List workflow runs for a workflow](https://docs.github.com/en/rest/actions/workflow-runs#list-workflow-runs-for-a-workflow)
82
-
83
- ### `.runJobs(runId: number)`
84
-
85
- Returns `ApiEndpoint<Job>`.
86
-
87
- Lists all jobs for a given workflow run.
88
-
89
- > GitHub docs: [List jobs for a workflow run](https://docs.github.com/en/rest/actions/workflow-jobs#list-jobs-for-a-workflow-run)
90
-
91
- ### `.runArtifacts(runId: number)`
92
-
93
- Returns `ApiEndpoint<Artifact>`.
94
-
95
- Lists all artifacts produced by a given workflow run.
96
-
97
- > GitHub docs: [List workflow run artifacts](https://docs.github.com/en/rest/actions/artifacts#list-workflow-run-artifacts)
package/docs/api/users.md DELETED
@@ -1,76 +0,0 @@
1
- # users
2
-
3
- The `users` proxy provides access to GitHub user endpoints.
4
-
5
- ```ts
6
- import { users } from "@openally/github.sdk";
7
-
8
- // Collect all repositories for a user
9
- const repos = await users.torvalds.repos().all();
10
-
11
- // Stream followers one by one
12
- for await (const follower of users.torvalds.followers().iterate()) {
13
- console.log(follower.login);
14
- }
15
-
16
- // Collect all starred repositories
17
- const starred = await users.torvalds.starred().all();
18
- ```
19
-
20
- ## Access pattern
21
-
22
- ```ts
23
- users[username].<method>()
24
- ```
25
-
26
- All methods return an [`ApiEndpoint<T>`](./ApiEndpoint.md) instance.
27
-
28
- ## Methods
29
-
30
- ### `.orgs()`
31
-
32
- Returns `ApiEndpoint<UserOrg>`.
33
-
34
- Lists all organizations the user belongs to.
35
-
36
- > GitHub docs: [List organizations for a user](https://docs.github.com/en/rest/orgs/orgs#list-organizations-for-a-user)
37
-
38
- ### `.repos()`
39
-
40
- Returns `ApiEndpoint<UserRepo>`.
41
-
42
- Lists all public repositories for the user.
43
-
44
- > GitHub docs: [List repositories for a user](https://docs.github.com/en/rest/repos/repos#list-repositories-for-a-user)
45
-
46
- ### `.gists()`
47
-
48
- Returns `ApiEndpoint<UserGist>`.
49
-
50
- Lists all public gists for the user.
51
-
52
- > GitHub docs: [List gists for a user](https://docs.github.com/en/rest/gists/gists#list-gists-for-a-user)
53
-
54
- ### `.followers()`
55
-
56
- Returns `ApiEndpoint<UserFollower>`.
57
-
58
- Lists all followers of the user.
59
-
60
- > GitHub docs: [List followers of a user](https://docs.github.com/en/rest/users/followers#list-followers-of-a-user)
61
-
62
- ### `.following()`
63
-
64
- Returns `ApiEndpoint<UserFollowing>`.
65
-
66
- Lists all users the user follows.
67
-
68
- > GitHub docs: [List the people a user follows](https://docs.github.com/en/rest/users/followers#list-the-people-a-user-follows)
69
-
70
- ### `.starred()`
71
-
72
- Returns `ApiEndpoint<UserStarred>`.
73
-
74
- Lists all repositories starred by the user.
75
-
76
- > GitHub docs: [List repositories starred by a user](https://docs.github.com/en/rest/activity/starring#list-repositories-starred-by-a-user)
package/eslint.config.mjs DELETED
@@ -1,3 +0,0 @@
1
- import { typescriptConfig } from "@openally/config.eslint";
2
-
3
- export default typescriptConfig();
package/src/api/repos.ts DELETED
@@ -1,74 +0,0 @@
1
- // Import Internal Dependencies
2
- import { ApiEndpoint } from "../class/ApiEndpoint.ts";
3
- import { createApiProxy } from "../class/createApiProxy.ts";
4
- import type {
5
- Tag,
6
- PullRequest,
7
- Issue,
8
- Commit,
9
- Workflow,
10
- WorkflowRun,
11
- Job,
12
- Artifact,
13
- WorkflowsResponse,
14
- WorkflowRunsResponse,
15
- JobsResponse,
16
- ArtifactsResponse,
17
- RequestConfig
18
- } from "../types.ts";
19
-
20
- type RepoEndpointMethods = {
21
- tags: () => ApiEndpoint<Tag>;
22
- pulls: () => ApiEndpoint<PullRequest>;
23
- issues: () => ApiEndpoint<Issue>;
24
- commits: () => ApiEndpoint<Commit>;
25
- workflows: () => ApiEndpoint<Workflow>;
26
- workflowRuns: (workflowId: string | number) => ApiEndpoint<WorkflowRun>;
27
- runJobs: (runId: number) => ApiEndpoint<Job>;
28
- runArtifacts: (runId: number) => ApiEndpoint<Artifact>;
29
- };
30
-
31
- export type ReposProxy = {
32
- [owner: string]: {
33
- [repo: string]: RepoEndpointMethods;
34
- };
35
- };
36
-
37
- function createRepoProxy(
38
- owner: string,
39
- repo: string,
40
- config: RequestConfig = {}
41
- ): RepoEndpointMethods {
42
- return {
43
- tags: () => new ApiEndpoint<Tag>(`/repos/${owner}/${repo}/tags`, config),
44
- pulls: () => new ApiEndpoint<PullRequest>(`/repos/${owner}/${repo}/pulls`, config),
45
- issues: () => new ApiEndpoint<Issue>(`/repos/${owner}/${repo}/issues`, config),
46
- commits: () => new ApiEndpoint<Commit>(`/repos/${owner}/${repo}/commits`, config),
47
- workflows: () => new ApiEndpoint<Workflow>(
48
- `/repos/${owner}/${repo}/actions/workflows`,
49
- { ...config, extractor: (raw: WorkflowsResponse) => raw.workflows }
50
- ),
51
- workflowRuns: (workflowId: string | number) => new ApiEndpoint<WorkflowRun>(
52
- `/repos/${owner}/${repo}/actions/workflows/${workflowId}/runs`,
53
- { ...config, extractor: (raw: WorkflowRunsResponse) => raw.workflow_runs }
54
- ),
55
- runJobs: (runId: number) => new ApiEndpoint<Job>(
56
- `/repos/${owner}/${repo}/actions/runs/${runId}/jobs`,
57
- { ...config, extractor: (raw: JobsResponse) => raw.jobs }
58
- ),
59
- runArtifacts: (runId: number) => new ApiEndpoint<Artifact>(
60
- `/repos/${owner}/${repo}/actions/runs/${runId}/artifacts`,
61
- { ...config, extractor: (raw: ArtifactsResponse) => raw.artifacts }
62
- )
63
- };
64
- }
65
-
66
- export function createReposProxy(config: RequestConfig = {}): ReposProxy {
67
- return createApiProxy(
68
- (owner) => createApiProxy(
69
- (repo) => createRepoProxy(owner, repo, config)
70
- )
71
- ) as ReposProxy;
72
- }
73
-
74
- export const repos = createReposProxy();
package/src/api/users.ts DELETED
@@ -1,47 +0,0 @@
1
- // Import Internal Dependencies
2
- import { ApiEndpoint } from "../class/ApiEndpoint.ts";
3
- import { createApiProxy } from "../class/createApiProxy.ts";
4
- import type {
5
- UserOrg,
6
- UserRepo,
7
- UserGist,
8
- UserFollower,
9
- UserFollowing,
10
- UserStarred,
11
- RequestConfig
12
- } from "../types.ts";
13
-
14
- // CONSTANTS
15
- const kUserEndpointResponseMap = {
16
- orgs: {} as UserOrg,
17
- repos: {} as UserRepo,
18
- gists: {} as UserGist,
19
- followers: {} as UserFollower,
20
- following: {} as UserFollowing,
21
- starred: {} as UserStarred
22
- };
23
-
24
- type UserEndpoint = keyof typeof kUserEndpointResponseMap;
25
- type UserEndpointMethods = {
26
- [K in UserEndpoint]: () => ApiEndpoint<typeof kUserEndpointResponseMap[K]>;
27
- };
28
- export type UsersProxy = {
29
- [username: string]: UserEndpointMethods;
30
- };
31
-
32
- function createUserProxy(
33
- username: string,
34
- config: RequestConfig = {}
35
- ): UserEndpointMethods {
36
- return Object.fromEntries(
37
- (Object.keys(kUserEndpointResponseMap) as UserEndpoint[]).map(
38
- (endpoint) => [endpoint, () => new ApiEndpoint(`/users/${username}/${endpoint}`, config)]
39
- )
40
- ) as UserEndpointMethods;
41
- }
42
-
43
- export function createUsersProxy(config: RequestConfig = {}): UsersProxy {
44
- return createApiProxy((username) => createUserProxy(username, config)) as UsersProxy;
45
- }
46
-
47
- export const users = createUsersProxy();