@kosha-ai/integration-github 0.0.5 → 0.1.0
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.
- package/dist/lib/integration-github.d.ts.map +1 -1
- package/dist/lib/integration-github.js +28 -0
- package/docs/images/github-client-secret.png +0 -0
- package/docs/images/github-oauth-apps.png +0 -0
- package/docs/images/github-register-app.png +0 -0
- package/docs/setup.md +29 -0
- package/package.json +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration-github.d.ts","sourceRoot":"","sources":["../../src/lib/integration-github.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"integration-github.d.ts","sourceRoot":"","sources":["../../src/lib/integration-github.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAQlE,MAAM,WAAW,wBAAwB;IACvC,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAiBD,wBAAgB,MAAM,CACpB,OAAO,GAAE,wBAA6B,GACrC,gBAAgB,CA4DlB;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { defineIntegration, oauth2 } from '@kosha-ai/integration-sdk';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
const docsDirectory = path.join(currentDir, '../../docs');
|
|
6
|
+
/**
|
|
7
|
+
* The hosts a `git clone` talks to. github.com redirects pack fetches to
|
|
8
|
+
* codeload.github.com, which needs the same credential; a GitHub Enterprise
|
|
9
|
+
* Server instance serves both from its own host.
|
|
10
|
+
*/
|
|
11
|
+
function gitHosts(webBaseUrl) {
|
|
12
|
+
const host = new URL(webBaseUrl).hostname;
|
|
13
|
+
return host === 'github.com' ? [host, 'codeload.github.com'] : [host];
|
|
14
|
+
}
|
|
2
15
|
export function github(options = {}) {
|
|
3
16
|
const apiBaseUrl = options.baseUrl ?? 'https://api.github.com';
|
|
4
17
|
const webBaseUrl = options.webBaseUrl ?? 'https://github.com';
|
|
@@ -6,6 +19,7 @@ export function github(options = {}) {
|
|
|
6
19
|
key: 'github',
|
|
7
20
|
name: 'GitHub',
|
|
8
21
|
docsUrl: 'https://docs.github.com/rest',
|
|
22
|
+
docsPath: docsDirectory,
|
|
9
23
|
auth: oauth2({
|
|
10
24
|
authorizationUrl: `${webBaseUrl}/login/oauth/authorize`,
|
|
11
25
|
tokenUrl: `${webBaseUrl}/login/oauth/access_token`,
|
|
@@ -30,6 +44,20 @@ export function github(options = {}) {
|
|
|
30
44
|
Accept: 'application/vnd.github+json',
|
|
31
45
|
'X-GitHub-Api-Version': '2022-11-28',
|
|
32
46
|
}),
|
|
47
|
+
egress: [
|
|
48
|
+
{
|
|
49
|
+
hosts: gitHosts(webBaseUrl),
|
|
50
|
+
// Git's smart-HTTP transport wants Basic, not Bearer. GitHub ignores
|
|
51
|
+
// the username for a token credential but requires one, and
|
|
52
|
+
// `x-access-token` is the documented placeholder.
|
|
53
|
+
headers: ({ accessToken }) => ({
|
|
54
|
+
authorization: `Basic ${Buffer.from(`x-access-token:${accessToken}`).toString('base64')}`,
|
|
55
|
+
}),
|
|
56
|
+
},
|
|
57
|
+
// No `headers`, so the REST API gets what `authHeaders` builds and a
|
|
58
|
+
// call from a sandbox looks identical to one through the proxy.
|
|
59
|
+
{ hosts: [new URL(apiBaseUrl).hostname] },
|
|
60
|
+
],
|
|
33
61
|
},
|
|
34
62
|
identity: {
|
|
35
63
|
async fetchAccount({ accessToken, http }) {
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/docs/setup.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# GitHub Setup
|
|
2
|
+
|
|
3
|
+
To connect to GitHub, you need to create a GitHub OAuth App. This allows Kosha to act on behalf of your users.
|
|
4
|
+
|
|
5
|
+
### 1. Register a new OAuth application
|
|
6
|
+
|
|
7
|
+
1. Go to your GitHub account settings.
|
|
8
|
+
2. In the left sidebar, scroll down to **Developer settings**.
|
|
9
|
+
3. Select **OAuth Apps** and click **New OAuth App**.
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
4. Fill in the application details:
|
|
14
|
+
- **Application name**: The name of your application.
|
|
15
|
+
- **Homepage URL**: Your website URL.
|
|
16
|
+
- **Authorization callback URL**: Your Kosha redirect URI (e.g. `https://your-app.com/api/connect/github/callback`).
|
|
17
|
+
|
|
18
|
+

|
|
19
|
+
|
|
20
|
+
### 2. Generate Client Secret
|
|
21
|
+
|
|
22
|
+
1. Once created, you will see your **Client ID**.
|
|
23
|
+
2. Click on **Generate a new client secret**.
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+
|
|
27
|
+
3. Copy both the **Client ID** and **Client Secret** and paste them into the Kosha configuration form.
|
|
28
|
+
|
|
29
|
+
> **Note:** GitHub OAuth Apps do not require you to define scopes upfront. Scopes are requested dynamically when the user initiates the connection.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosha-ai/integration-github",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "GitHub integration for Kosha",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kosha",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"files": [
|
|
38
38
|
"dist",
|
|
39
|
+
"docs",
|
|
39
40
|
"!**/*.tsbuildinfo"
|
|
40
41
|
],
|
|
41
42
|
"dependencies": {
|
|
@@ -46,9 +47,9 @@
|
|
|
46
47
|
"key": "github"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
|
-
"@kosha-ai/integration-sdk": "0.0
|
|
50
|
+
"@kosha-ai/integration-sdk": "0.1.0"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@kosha-ai/integration-sdk": "0.0
|
|
53
|
+
"@kosha-ai/integration-sdk": "0.1.0"
|
|
53
54
|
}
|
|
54
55
|
}
|