@slates-integrations/github 0.2.0-rc.2

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 (45) hide show
  1. package/README.md +109 -0
  2. package/docs/SPEC.md +215 -0
  3. package/logo.png +0 -0
  4. package/package.json +18 -0
  5. package/slate.json +22 -0
  6. package/src/auth.ts +257 -0
  7. package/src/config.ts +4 -0
  8. package/src/index.ts +78 -0
  9. package/src/lib/client.ts +974 -0
  10. package/src/spec.ts +13 -0
  11. package/src/tools/comment-on-issue.ts +46 -0
  12. package/src/tools/create-commit-status.ts +97 -0
  13. package/src/tools/create-release.ts +69 -0
  14. package/src/tools/create-repository.ts +70 -0
  15. package/src/tools/get-issue.ts +67 -0
  16. package/src/tools/get-repository.ts +75 -0
  17. package/src/tools/get-user.ts +64 -0
  18. package/src/tools/index.ts +24 -0
  19. package/src/tools/list-branches.ts +54 -0
  20. package/src/tools/list-commits.ts +70 -0
  21. package/src/tools/list-issues.ts +90 -0
  22. package/src/tools/list-pull-requests.ts +82 -0
  23. package/src/tools/list-repositories.ts +102 -0
  24. package/src/tools/manage-collaborators.ts +88 -0
  25. package/src/tools/manage-file-content.ts +117 -0
  26. package/src/tools/manage-gist.ts +183 -0
  27. package/src/tools/manage-issue.ts +94 -0
  28. package/src/tools/manage-labels.ts +93 -0
  29. package/src/tools/manage-pull-request.ts +111 -0
  30. package/src/tools/manage-workflow.ts +242 -0
  31. package/src/tools/merge-pull-request.ts +61 -0
  32. package/src/tools/review-pull-request.ts +90 -0
  33. package/src/tools/search.ts +72 -0
  34. package/src/tools/star-repository.ts +57 -0
  35. package/src/tools/update-repository.ts +56 -0
  36. package/src/triggers/index.ts +8 -0
  37. package/src/triggers/issue-comment.ts +94 -0
  38. package/src/triggers/issues.ts +111 -0
  39. package/src/triggers/pull-request-review.ts +95 -0
  40. package/src/triggers/pull-request.ts +123 -0
  41. package/src/triggers/push.ts +117 -0
  42. package/src/triggers/release.ts +103 -0
  43. package/src/triggers/star.ts +71 -0
  44. package/src/triggers/workflow-run.ts +112 -0
  45. package/tsconfig.json +23 -0
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # <img src="https://provider-logos.metorial-cdn.com/github.png" height="20"> Github
2
+
3
+ Manage repositories, issues, and pull requests. Create and configure branches, star repositories, review code, and merge changes. Automate CI/CD workflows with GitHub Actions, manage workflow runs, secrets, and artifacts. Track issues with labels, milestones, and assignees. Search across code, repositories, issues, and users. Manage organizations, teams, and memberships. Create and manage projects, gists, packages, deployments, and environments. Access security alerts including code scanning, secret scanning, and Dependabot alerts. Read and write file contents in repositories. Manage webhooks, notifications, and codespaces.
4
+
5
+ ## Tools
6
+
7
+ ### Comment on Issue
8
+
9
+ Add a comment to an existing issue or pull request. Both issues and pull requests share the same comment API.
10
+
11
+ ### Create Commit Status
12
+
13
+ Create a status check on a specific commit. Useful for integrating CI/CD results, deployment status, or other external checks. Also supports reading the combined status of all checks for a given ref.
14
+
15
+ ### Create Release
16
+
17
+ Create a new release for a GitHub repository with a tag, name, release notes, and draft/pre-release options. Can automatically generate release notes from commits since the last release.
18
+
19
+ ### Create Repository
20
+
21
+ Create a new GitHub repository for the authenticated user or within an organization. Supports initializing with a README, gitignore template, and license.
22
+
23
+ ### Get Issue
24
+
25
+ Retrieve detailed information about a specific issue, including its body, comments count, labels, assignees, and milestone.
26
+
27
+ ### Get Repository
28
+
29
+ Retrieve detailed information about a GitHub repository including its settings, statistics, and metadata. Use this to inspect a repository's configuration, check its visibility, default branch, language, star/fork counts, and more.
30
+
31
+ ### Get User
32
+
33
+ Retrieve a GitHub user's profile. Provide a username to look up any user, or omit it to get the authenticated user's profile.
34
+
35
+ ### Star Repository
36
+
37
+ Star or unstar a GitHub repository for the authenticated user.
38
+
39
+ ### List Branches
40
+
41
+ List branches in a GitHub repository with optional filtering for protected branches.
42
+
43
+ ### List Commits
44
+
45
+ List commits on a repository branch with filtering by SHA, path, author, or date range.
46
+
47
+ ### List Issues
48
+
49
+ List issues in a GitHub repository with filtering and sorting options. Filter by state, labels, assignee, milestone, and since date. Note: GitHub's API returns pull requests alongside issues — this tool filters them out.
50
+
51
+ ### List Pull Requests
52
+
53
+ List pull requests in a GitHub repository with filtering by state, head/base branch, and sorting options.
54
+
55
+ ### List Repositories
56
+
57
+ List repositories for the authenticated user or a specific organization. Supports filtering by type, sorting, and pagination.
58
+
59
+ ### Manage Collaborators
60
+
61
+ List, add, or remove collaborators on a GitHub repository. Control access permissions for individual users.
62
+
63
+ ### Manage File Content
64
+
65
+ Read, create, update, or delete a file in a GitHub repository. - **read**: Retrieve file contents (decoded from Base64). - **write**: Create or update a file. Provide Base64-encoded content and a commit message. - **delete**: Delete a file. Requires the file's current SHA and a commit message.
66
+
67
+ ### Manage Gist
68
+
69
+ Create, read, update, or delete GitHub Gists (code snippets). - **create**: Create a new gist with one or more files. - **get**: Retrieve a gist by ID. - **update**: Update a gist's description or files. - **delete**: Delete a gist. - **list**: List gists for the authenticated user.
70
+
71
+ ### Manage Issue
72
+
73
+ Create a new issue or update an existing one in a GitHub repository. When creating: provide title and optionally body, labels, assignees, and milestone. When updating: provide the issue number along with fields to change (title, body, state, labels, assignees).
74
+
75
+ ### Manage Labels
76
+
77
+ List existing labels or create a new label in a GitHub repository. Labels can be applied to issues and pull requests for categorization.
78
+
79
+ ### Manage Pull Request
80
+
81
+ Create a new pull request or update an existing one. When creating: provide head branch, base branch, and title. When updating: provide the pull request number along with fields to change.
82
+
83
+ ### Manage Workflow
84
+
85
+ Interact with GitHub Actions workflows: list workflows, list runs, trigger a workflow dispatch, cancel or rerun a workflow run, and view run jobs.
86
+
87
+ ### Merge Pull Request
88
+
89
+ Merge a pull request using the specified merge method (merge commit, squash, or rebase).
90
+
91
+ ### Review Pull Request
92
+
93
+ Submit a review on a pull request with an approve, request changes, or comment action. Optionally include inline comments on specific files and lines. Can also request reviewers.
94
+
95
+ ### Search GitHub
96
+
97
+ Search across GitHub for repositories, code, issues/pull requests, or users using GitHub's search syntax. Supports qualifiers for filtering (e.g., "language:python stars:>100" for repositories).
98
+
99
+ ### Update Repository
100
+
101
+ Update settings of an existing GitHub repository. Modify name, description, visibility, feature toggles (issues, wiki, projects), default branch, and archive status.
102
+
103
+ ## License
104
+
105
+ This integration is licensed under the [FSL-1.1](https://github.com/metorial/metorial-platform/blob/dev/LICENSE).
106
+
107
+ <div align="center">
108
+ <sub>Built with ❤️ by <a href="https://metorial.com">Metorial</a></sub>
109
+ </div>
package/docs/SPEC.md ADDED
@@ -0,0 +1,215 @@
1
+ Now I have enough information to write the specification. Let me compile everything.
2
+
3
+ # Slates Specification for GitHub
4
+
5
+ ## Overview
6
+
7
+ GitHub is a cloud-based platform for version control and collaboration using Git. It provides hosting for software repositories along with features for issue tracking, code review, project management, CI/CD (GitHub Actions), and package hosting. GitHub offers both REST and GraphQL APIs for programmatic access to its platform resources.
8
+
9
+ ## Authentication
10
+
11
+ GitHub supports several authentication methods for API access:
12
+
13
+ ### 1. Personal Access Tokens (PATs)
14
+
15
+ Personal Access Tokens are preferred over passwords and provide granular control over permissions, enabling developers to create tokens that allow only specific actions. There are two types:
16
+
17
+ - **Fine-grained PATs** (recommended): Allow selecting specific repositories and precise permissions. Generated under **Settings > Developer settings > Personal access tokens > Fine-grained tokens**.
18
+ - **Classic PATs**: Use OAuth scopes for permission control. Generated under **Settings > Developer settings > Personal access tokens > Tokens (classic)**.
19
+
20
+ Tokens are passed via the `Authorization` header:
21
+
22
+ ```
23
+ Authorization: Bearer <YOUR-TOKEN>
24
+ ```
25
+
26
+ ### 2. OAuth 2.0 (OAuth Apps)
27
+
28
+ Every registered OAuth app is assigned a unique Client ID and Client Secret. The client secret is used to get an access token for the signed-in user.
29
+
30
+ - **Authorization endpoint:** `https://github.com/login/oauth/authorize`
31
+ - **Token endpoint:** `https://github.com/login/oauth/access_token`
32
+ - **Flow:** Standard OAuth 2.0 Authorization Code flow. After a successful app authentication, GitHub provides a temporary code value, which must be POSTed back to GitHub with the client secret in exchange for an access token.
33
+
34
+ **Available OAuth Scopes:**
35
+
36
+ | Scope | Description |
37
+ | ------------------------------------------------------ | --------------------------------------------------------------------------- |
38
+ | `(no scope)` | Read-only access to public information |
39
+ | `repo` | Full access to public and private repositories |
40
+ | `repo:status` | Read/write access to commit statuses |
41
+ | `public_repo` | Access to public repositories only |
42
+ | `admin:org` | Full management of organizations and teams |
43
+ | `write:org` / `read:org` | Write or read access to organization membership |
44
+ | `admin:repo_hook` | Full access to repository webhooks |
45
+ | `admin:org_hook` | Full access to organization webhooks |
46
+ | `user` | Read/write access to user profile (includes `user:email` and `user:follow`) |
47
+ | `user:email` | Read access to email addresses |
48
+ | `gist` | Write access to gists |
49
+ | `notifications` | Access to notifications |
50
+ | `workflow` | Manage GitHub Actions workflow files |
51
+ | `write:packages` / `read:packages` / `delete:packages` | Manage GitHub Packages |
52
+ | `project` / `read:project` | Access to user and organization projects |
53
+ | `delete_repo` | Delete repositories |
54
+ | `codespace` | Create and manage codespaces |
55
+ | `security_events` | Access to code scanning API |
56
+ | `read:audit_log` | Read audit log data |
57
+
58
+ ### 3. GitHub Apps
59
+
60
+ GitHub Apps authentication allows third-party applications to act on behalf of a user or organization, involving creating a GitHub App, installing it on a user or organization's account, and authenticating requests using a private key.
61
+
62
+ - **Authentication as the app:** Generate a JSON Web Token (JWT) signed with the app's private key, then use it to obtain an installation access token.
63
+ - **Authentication on behalf of a user:** Uses an OAuth-like flow to obtain a user access token.
64
+ - GitHub Apps use fine-grained permissions instead of scopes, which give you more control over what your app can do.
65
+
66
+ ### Base URL
67
+
68
+ All API requests are made to `https://api.github.com`.
69
+
70
+ ## Features
71
+
72
+ ### Repository Management
73
+
74
+ Create, read, update, and delete repositories. Manage repository settings including visibility (public/private), branch protection rules, collaborator access, deploy keys, and repository topics. Also supports forking, transferring ownership, and managing repository templates.
75
+
76
+ ### Issues and Issue Tracking
77
+
78
+ Create and manage issues within repositories. Supports labels, milestones, assignees, and comments. Issues can be searched and filtered across repositories using a powerful search syntax.
79
+
80
+ ### Pull Requests and Code Review
81
+
82
+ Create and manage pull requests including requesting reviewers, managing review comments, and merging. Supports diff and patch formats. Allows managing pull request reviews with approve, request-changes, and comment actions.
83
+
84
+ ### Git Data
85
+
86
+ Low-level access to Git objects including blobs, trees, commits, refs, and tags. Allows reading and writing raw Git data in a repository.
87
+
88
+ ### GitHub Actions and Workflows
89
+
90
+ Manage workflows, workflow runs, and artifacts. Trigger workflows, view run logs, and manage workflow secrets and variables. Also supports managing self-hosted runners.
91
+
92
+ ### Organizations and Teams
93
+
94
+ Manage organization settings, memberships, teams, and team memberships. Control organization-level permissions, invitations, and outside collaborator access.
95
+
96
+ ### Users and Profiles
97
+
98
+ Access and update user profile information, email addresses, SSH keys, GPG keys, and social accounts. View followers and following relationships.
99
+
100
+ ### Projects
101
+
102
+ Create and manage GitHub Projects (the project board feature). Supports managing columns and cards for organizing issues and pull requests.
103
+
104
+ ### Gists
105
+
106
+ Create, update, delete, and list gists (code snippets). Supports forking, starring, and commenting on gists.
107
+
108
+ ### GitHub Packages
109
+
110
+ Publish, install, and manage packages. Supports multiple package ecosystems including npm, Maven, Docker, NuGet, and RubyGems.
111
+
112
+ ### Code Search and Repository Search
113
+
114
+ Search across code, repositories, issues, pull requests, users, topics, and commits using GitHub's search syntax. Supports qualifiers for filtering results.
115
+
116
+ ### Deployments and Environments
117
+
118
+ Using the Deployments REST API, you can build custom tooling that interacts with your server and a third-party app. Manage deployment statuses and environments for repositories.
119
+
120
+ ### Checks and Commit Statuses
121
+
122
+ You can use the REST API to build GitHub Apps that run powerful checks against code changes in a repository. Create and manage check runs, check suites, and commit statuses for CI/CD integration.
123
+
124
+ ### Content Management
125
+
126
+ Use the REST API to create, modify, and delete Base64 encoded content in a repository. Read and write files, directories, and symlinks within repositories.
127
+
128
+ ### Notifications
129
+
130
+ Access and manage notification threads for watched repositories and subscriptions.
131
+
132
+ ### Security and Code Scanning
133
+
134
+ Access code scanning alerts, secret scanning alerts, Dependabot alerts, and security advisories. Manage repository vulnerability settings.
135
+
136
+ ### Codespaces
137
+
138
+ Create, manage, and delete cloud development environments. Configure machine types and manage secrets for codespaces.
139
+
140
+ ### GraphQL API
141
+
142
+ In addition to the REST API, GitHub provides a GraphQL API (v4) that allows more flexible, efficient queries with the ability to request exactly the data needed in a single request.
143
+
144
+ ## Events
145
+
146
+ Webhooks provide a way for notifications to be delivered to an external web server whenever certain events occur on GitHub. Webhooks let you subscribe to events happening in a software system and automatically receive a delivery of data to your server whenever those events occur.
147
+
148
+ You can create webhooks in a repository to subscribe to events that occur in that repository. You can create webhooks to subscribe to events that occur in a specific repository, organization, GitHub Marketplace account, GitHub Sponsors account, or GitHub App.
149
+
150
+ Webhooks are configured with a payload URL, content type (JSON or form), and an optional secret for signature verification. The webhook signature header is the HMAC hex digest of the request body, generated using the SHA-256 hash function and the secret as the HMAC key.
151
+
152
+ ### Code & Repository Events
153
+
154
+ - **Push:** Triggered when commits are pushed to a branch or tag.
155
+ - **Create / Delete:** Triggered when a branch or tag is created or deleted.
156
+ - **Repository:** Triggered when a repository is created, deleted, archived, made public/private, or transferred.
157
+ - **Fork:** Triggered when a repository is forked.
158
+ - **Release:** Triggered when a release is published, edited, or deleted (including pre-releases).
159
+ - **Commit Comment:** Triggered when a comment is made on a commit.
160
+
161
+ ### Pull Request Events
162
+
163
+ - **Pull Request:** Triggered for activity on pull requests (opened, closed, merged, assigned, labeled, review requested, etc.). Configurable by action type.
164
+ - **Pull Request Review:** Triggered when a review is submitted, edited, or dismissed.
165
+ - **Pull Request Review Comment:** Triggered for comments on a pull request diff.
166
+ - **Pull Request Review Thread:** Triggered when a comment thread on a pull request is resolved or unresolved.
167
+
168
+ ### Issue Events
169
+
170
+ - **Issues:** Triggered for issue activity (opened, edited, closed, assigned, labeled, etc.).
171
+ - **Issue Comment:** Triggered when a comment is created, edited, or deleted on an issue or pull request.
172
+ - **Label:** Triggered when a label is created, edited, or deleted.
173
+ - **Milestone:** Triggered when a milestone is created, closed, edited, or deleted.
174
+
175
+ ### CI/CD and Checks Events
176
+
177
+ - **Check Run / Check Suite:** Triggered for check run and check suite lifecycle events (created, completed, rerequested).
178
+ - **Workflow Job:** Triggered when a GitHub Actions workflow job is queued, in progress, or completed.
179
+ - **Workflow Run:** Triggered when a workflow run is requested, completed, or in progress.
180
+ - **Deployment / Deployment Status:** Triggered when a deployment is created or its status changes.
181
+ - **Status:** Triggered when the status of a commit changes.
182
+
183
+ ### Organization and Team Events
184
+
185
+ - **Organization:** Triggered for organization-level events (member added/removed, renamed, etc.).
186
+ - **Team:** Triggered when a team is created, deleted, edited, or has members/repos added/removed.
187
+ - **Membership:** Triggered when a user is added to or removed from a team.
188
+ - **Member:** Triggered when a collaborator is added to a repository.
189
+
190
+ ### Security Events
191
+
192
+ - **Code Scanning Alert:** Triggered when a code scanning alert is created, fixed, or dismissed.
193
+ - **Secret Scanning Alert:** Triggered when a secret scanning alert is created, resolved, or reopened.
194
+ - **Dependabot Alert:** Triggered for Dependabot vulnerability alert activity.
195
+ - **Repository Vulnerability Alert:** Triggered when a security vulnerability is detected.
196
+
197
+ ### Discussion Events
198
+
199
+ - **Discussion:** Triggered for GitHub Discussions activity (created, edited, answered, etc.).
200
+ - **Discussion Comment:** Triggered when a comment on a discussion is created, edited, or deleted.
201
+
202
+ ### Project Events
203
+
204
+ - **Projects V2 Item:** Triggered when an item in a GitHub Project is created, edited, or deleted.
205
+
206
+ ### Other Events
207
+
208
+ - **Star:** Triggered when a repository is starred or unstarred.
209
+ - **Watch:** Triggered when a user watches a repository.
210
+ - **Wiki (Gollum):** Triggered when a wiki page is created or updated.
211
+ - **Page Build:** Triggered when a GitHub Pages site is built.
212
+ - **Package:** Triggered when a package is published or updated in GitHub Packages.
213
+ - **Sponsorship:** Triggered for GitHub Sponsors activity.
214
+ - **Marketplace Purchase:** Triggered for GitHub Marketplace purchase activity.
215
+ - **Ping:** A special event sent when a webhook is first created to verify the connection.
package/logo.png ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@slates-integrations/github",
3
+ "main": "src/index.ts",
4
+ "type": "module",
5
+ "scripts": {
6
+ "build": "bunx @vercel/ncc build src/index.ts -o dist -m -s",
7
+ "typecheck": "tsc --noEmit"
8
+ },
9
+ "dependencies": {
10
+ "@types/node": "^20",
11
+ "slates": "1.0.0-rc.9",
12
+ "zod": "^4.2"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "^5"
16
+ },
17
+ "version": "0.2.0-rc.2"
18
+ }
package/slate.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@github/github",
3
+ "description": "Manage repositories, issues, and pull requests. Create and configure branches, star repositories, review code, and merge changes. Automate CI/CD workflows with GitHub Actions, manage workflow runs, secrets, and artifacts. Track issues with labels, milestones, and assignees. Search across code, repositories, issues, and users. Manage organizations, teams, and memberships. Create and manage projects, gists, packages, deployments, and environments. Access security alerts including code scanning, secret scanning, and Dependabot alerts. Read and write file contents in repositories. Manage webhooks, notifications, and codespaces.",
4
+ "categories": [
5
+ "apis-and-http-requests",
6
+ "task-and-project-management"
7
+ ],
8
+ "skills": [
9
+ "manage repositories",
10
+ "star repositories",
11
+ "create pull requests",
12
+ "track issues",
13
+ "review and merge code",
14
+ "automate CI/CD workflows",
15
+ "search code and repositories",
16
+ "manage organizations and teams",
17
+ "read and write file contents",
18
+ "manage security alerts",
19
+ "configure webhooks"
20
+ ],
21
+ "logoUrl": "https://provider-logos.metorial-cdn.com/github.png"
22
+ }
package/src/auth.ts ADDED
@@ -0,0 +1,257 @@
1
+ import { SlateAuth, createAxios } from 'slates';
2
+ import { z } from 'zod';
3
+
4
+ export let auth = SlateAuth.create()
5
+ .output(
6
+ z.object({
7
+ token: z.string(),
8
+ refreshToken: z.string().optional()
9
+ })
10
+ )
11
+ .addOauth({
12
+ type: 'auth.oauth',
13
+ name: 'OAuth',
14
+ key: 'oauth',
15
+
16
+ scopes: [
17
+ {
18
+ title: 'Repository',
19
+ description: 'Full access to public and private repositories',
20
+ scope: 'repo'
21
+ },
22
+ {
23
+ title: 'Repository Status',
24
+ description: 'Read/write access to commit statuses',
25
+ scope: 'repo:status'
26
+ },
27
+ {
28
+ title: 'Public Repository',
29
+ description: 'Access to public repositories only',
30
+ scope: 'public_repo'
31
+ },
32
+ {
33
+ title: 'Admin: Organization',
34
+ description: 'Full management of organizations and teams',
35
+ scope: 'admin:org'
36
+ },
37
+ {
38
+ title: 'Write Organization',
39
+ description: 'Write access to organization membership',
40
+ scope: 'write:org'
41
+ },
42
+ {
43
+ title: 'Read Organization',
44
+ description: 'Read access to organization membership',
45
+ scope: 'read:org'
46
+ },
47
+ {
48
+ title: 'Admin: Repo Hook',
49
+ description: 'Full access to repository webhooks',
50
+ scope: 'admin:repo_hook'
51
+ },
52
+ {
53
+ title: 'Admin: Org Hook',
54
+ description: 'Full access to organization webhooks',
55
+ scope: 'admin:org_hook'
56
+ },
57
+ {
58
+ title: 'User',
59
+ description: 'Read/write access to user profile, email, and follow',
60
+ scope: 'user'
61
+ },
62
+ {
63
+ title: 'User Email',
64
+ description: 'Read access to email addresses',
65
+ scope: 'user:email'
66
+ },
67
+ {
68
+ title: 'Gist',
69
+ description: 'Write access to gists',
70
+ scope: 'gist'
71
+ },
72
+ {
73
+ title: 'Notifications',
74
+ description: 'Access to notifications',
75
+ scope: 'notifications'
76
+ },
77
+ {
78
+ title: 'Workflow',
79
+ description: 'Manage GitHub Actions workflow files',
80
+ scope: 'workflow'
81
+ },
82
+ {
83
+ title: 'Write Packages',
84
+ description: 'Upload packages to GitHub Packages',
85
+ scope: 'write:packages'
86
+ },
87
+ {
88
+ title: 'Read Packages',
89
+ description: 'Download packages from GitHub Packages',
90
+ scope: 'read:packages'
91
+ },
92
+ {
93
+ title: 'Delete Packages',
94
+ description: 'Delete packages from GitHub Packages',
95
+ scope: 'delete:packages'
96
+ },
97
+ {
98
+ title: 'Project',
99
+ description: 'Full access to user and organization projects',
100
+ scope: 'project'
101
+ },
102
+ {
103
+ title: 'Read Project',
104
+ description: 'Read-only access to user and organization projects',
105
+ scope: 'read:project'
106
+ },
107
+ {
108
+ title: 'Delete Repository',
109
+ description: 'Delete repositories',
110
+ scope: 'delete_repo'
111
+ },
112
+ {
113
+ title: 'Security Events',
114
+ description: 'Access to code scanning API',
115
+ scope: 'security_events'
116
+ },
117
+ {
118
+ title: 'Read Audit Log',
119
+ description: 'Read audit log data',
120
+ scope: 'read:audit_log'
121
+ }
122
+ ],
123
+
124
+ getAuthorizationUrl: async ctx => {
125
+ let params = new URLSearchParams({
126
+ client_id: ctx.clientId,
127
+ redirect_uri: ctx.redirectUri,
128
+ state: ctx.state,
129
+ scope: ctx.scopes.join(' ')
130
+ });
131
+
132
+ return {
133
+ url: `https://github.com/login/oauth/authorize?${params.toString()}`
134
+ };
135
+ },
136
+
137
+ handleCallback: async ctx => {
138
+ let http = createAxios();
139
+
140
+ let response = await http.post(
141
+ 'https://github.com/login/oauth/access_token',
142
+ {
143
+ client_id: ctx.clientId,
144
+ client_secret: ctx.clientSecret,
145
+ code: ctx.code,
146
+ redirect_uri: ctx.redirectUri
147
+ },
148
+ {
149
+ headers: {
150
+ Accept: 'application/json'
151
+ }
152
+ }
153
+ );
154
+
155
+ let data = response.data;
156
+
157
+ return {
158
+ output: {
159
+ token: data.access_token,
160
+ refreshToken: data.refresh_token
161
+ }
162
+ };
163
+ },
164
+
165
+ handleTokenRefresh: async ctx => {
166
+ if (!ctx.output.refreshToken) {
167
+ return { output: ctx.output };
168
+ }
169
+
170
+ let http = createAxios();
171
+
172
+ let response = await http.post(
173
+ 'https://github.com/login/oauth/access_token',
174
+ {
175
+ client_id: ctx.clientId,
176
+ client_secret: ctx.clientSecret,
177
+ grant_type: 'refresh_token',
178
+ refresh_token: ctx.output.refreshToken
179
+ },
180
+ {
181
+ headers: {
182
+ Accept: 'application/json'
183
+ }
184
+ }
185
+ );
186
+
187
+ let data = response.data;
188
+
189
+ return {
190
+ output: {
191
+ token: data.access_token,
192
+ refreshToken: data.refresh_token ?? ctx.output.refreshToken
193
+ }
194
+ };
195
+ },
196
+
197
+ getProfile: async (ctx: any) => {
198
+ let http = createAxios({
199
+ baseURL: 'https://api.github.com',
200
+ headers: {
201
+ Authorization: `Bearer ${ctx.output.token}`,
202
+ Accept: 'application/vnd.github+json'
203
+ }
204
+ });
205
+
206
+ let response = await http.get('/user');
207
+ let user = response.data;
208
+
209
+ return {
210
+ profile: {
211
+ id: String(user.id),
212
+ email: user.email ?? undefined,
213
+ name: user.name ?? user.login,
214
+ imageUrl: user.avatar_url
215
+ }
216
+ };
217
+ }
218
+ })
219
+ .addTokenAuth({
220
+ type: 'auth.token',
221
+ name: 'Personal Access Token',
222
+ key: 'personal_access_token',
223
+
224
+ inputSchema: z.object({
225
+ token: z.string().describe('GitHub Personal Access Token (classic or fine-grained)')
226
+ }),
227
+
228
+ getOutput: async ctx => {
229
+ return {
230
+ output: {
231
+ token: ctx.input.token
232
+ }
233
+ };
234
+ },
235
+
236
+ getProfile: async (ctx: any) => {
237
+ let http = createAxios({
238
+ baseURL: 'https://api.github.com',
239
+ headers: {
240
+ Authorization: `Bearer ${ctx.output.token}`,
241
+ Accept: 'application/vnd.github+json'
242
+ }
243
+ });
244
+
245
+ let response = await http.get('/user');
246
+ let user = response.data;
247
+
248
+ return {
249
+ profile: {
250
+ id: String(user.id),
251
+ email: user.email ?? undefined,
252
+ name: user.name ?? user.login,
253
+ imageUrl: user.avatar_url
254
+ }
255
+ };
256
+ }
257
+ });
package/src/config.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { SlateConfig } from 'slates';
2
+ import { z } from 'zod';
3
+
4
+ export let config = SlateConfig.create(z.object({}));