Skip to content

Commit

Permalink
feat: pass in token from kernel to authenticate octokit client
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Feb 18, 2024
1 parent e0c71d3 commit 1f4ba00
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: "Conversation Rewards"
description: "Compute rewards for contributors' discussion on issues that are closed as complete."
inputs:
authentication_token:
description: "The GitHub authentication token"
required: true
outputs:
result: # id of output
description: "The result of a event handler"
Expand All @@ -9,6 +13,6 @@ runs:
steps:
- run: |
yarn --cwd ${{ github.action_path }} --production=true
yarn --cwd ${{ github.action_path }} start
yarn --cwd ${{ github.action_path }} start --auth ${{ inputs.authentication_token }}
id: main
shell: bash
shell: bash
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
],
"dependencies": {
"@octokit/rest": "^20.0.2",
"dotenv": "^16.3.1"
"dotenv": "^16.3.1",
"yargs": "^17.7.2"
},
"devDependencies": {
"@commitlint/cli": "^18.4.3",
Expand All @@ -33,6 +34,7 @@
"@cspell/dict-software-terms": "^3.3.17",
"@cspell/dict-typescript": "^3.1.2",
"@types/node": "^20.10.0",
"@types/yargs": "^17.0.32",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"cspell": "^8.3.2",
Expand Down
19 changes: 19 additions & 0 deletions src/get-authentication-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Octokit } from "@octokit/rest";
import { parse } from "yargs";

let octokitInstance: Octokit | null = null;

function getAuthenticationToken(): string {
const argv = parse(process.argv.slice(2));
return argv.auth as string;
}

function getOctokitInstance(): Octokit {
if (!octokitInstance) {
const auth = getAuthenticationToken();
octokitInstance = new Octokit({ auth });
}
return octokitInstance;
}

export { getOctokitInstance };
13 changes: 9 additions & 4 deletions src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ function main(gitHubIssueId: GitHubIssue["id"]) {
const pullRequest = getLinkedPullRequest(issue);
const users = getUsers(issue, pullRequest);

const usersByType = {
assignees: users.filter((user) => user.isAssignee),
authors: users.filter((user) => user.isAuthor),
collaborators: users.filter((user) => user.isCollaborator),
remainder: users.filter((user) => user.isRemainder),
};

/**
* gather context
* * this includes:
Expand All @@ -21,14 +28,12 @@ function main(gitHubIssueId: GitHubIssue["id"]) {
* * * the users
* * * * isAssignee?
* * * * isAuthor?
* * * * isContributor?
* * * * isCollaborator?
* * * * isRemainder?
*/
}

function getIssue(issueId: GitHubIssue["id"]) {
// ...
}
function getIssue(issueId: GitHubIssue["id"]) {}

function getLinkedPullRequest(issue: GitHubIssue) {
// ...
Expand Down
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,18 @@
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.7.tgz#326f5fdda70d13580777bcaa1bc6fa772a5aef0e"
integrity sha512-/wdoPq1QqkSj9/QOeKkFquEuPzQbHTWAMPH/PaUMB+JuR31lXhlWXRZ52IpfDYVlDOUBvX09uBrPwxGT1hjNBg==

"@types/yargs-parser@*":
version "21.0.3"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.3.tgz#815e30b786d2e8f0dcd85fd5bcf5e1a04d008f15"
integrity sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==

"@types/yargs@^17.0.32":
version "17.0.32"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.32.tgz#030774723a2f7faafebf645f4e5a48371dca6229"
integrity sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==
dependencies:
"@types/yargs-parser" "*"

"@typescript-eslint/eslint-plugin@^6.13.1":
version "6.21.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.21.0.tgz#30830c1ca81fd5f3c2714e524c4303e0194f9cd3"
Expand Down Expand Up @@ -4639,7 +4651,7 @@ yargs-parser@^21.1.1:
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35"
integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==

yargs@^17.0.0:
yargs@^17.0.0, yargs@^17.7.2:
version "17.7.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269"
integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==
Expand Down

0 comments on commit 1f4ba00

Please sign in to comment.