diff --git a/action.yml b/action.yml index d4113d70..818c06ca 100644 --- a/action.yml +++ b/action.yml @@ -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" @@ -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 \ No newline at end of file + shell: bash diff --git a/package.json b/package.json index 05ac77a2..02c8c1ee 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/get-authentication-token.ts b/src/get-authentication-token.ts new file mode 100644 index 00000000..d7205d65 --- /dev/null +++ b/src/get-authentication-token.ts @@ -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 }; diff --git a/src/start.ts b/src/start.ts index 0abc69ee..e722f698 100644 --- a/src/start.ts +++ b/src/start.ts @@ -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: @@ -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) { // ... diff --git a/yarn.lock b/yarn.lock index e6af98f2..f807d235 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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==