generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56fb4de
commit a78d5e4
Showing
5 changed files
with
119 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,45 @@ | ||
import { calculateIssueReward, calculateRepoReward } from "./helpers/calculateReward"; | ||
import { calculateIssueReward, calculateOrgReward, calculateRepoReward } from "./helpers/calculateReward"; | ||
import { convertToCSV } from "./helpers/excel"; | ||
import { checkIfRepoExists } from "./helpers/github"; | ||
import { checkIfRepoExists, userExists } from "./helpers/github"; | ||
|
||
if (process.argv[2] == "--help") { | ||
console.log( | ||
"Usage: 'npx tsx src/index.ts ubiquity/ubiquibot' for the entire repo\n\nUsage: 'npx tsx src/index.ts ubiquity/ubiquibot' 223\nThe above command outputs the total reward for the issue with the number 223" | ||
"Usage: 'npx tsx src/index.ts ubiquity/ubiquibot' for the entire repo\n\nUsage: 'npx tsx src/index.ts ubiquity/ubiquibot' 223\nThe above command outputs the total reward for the issue with the number 223\n" | ||
); | ||
console.log("Usage: 'npx tsx src/index.ts ubiquity' for the entire user"); | ||
process.exit(); | ||
} | ||
|
||
const regexPattern = /^([\w-]+)\/([\w-]+)$/; | ||
const match = process.argv[2].match(regexPattern); | ||
const owner = match ? match[1] : null; | ||
const repo = match ? match[2] : null; | ||
|
||
if (!repo || !owner) { | ||
console.log("The repository you have provided does not match the pattern owner/repo"); | ||
if (!process.argv[2]) { | ||
console.log("Please provide argumet in terms of owner/repo or just owner"); | ||
process.exit(); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const exists = await checkIfRepoExists(owner, repo); | ||
if (!exists) { | ||
console.log("The repository you have provided does not exist"); | ||
process.exit(); | ||
|
||
const match = process.argv[2].split("/"); | ||
|
||
if (match.length > 2) { | ||
console.log("The argument you have provided you have provided does not match the syntax owner/repo or owner"); | ||
} | ||
|
||
const owner = match[0]; | ||
const repo = match[1] ?? null; | ||
|
||
if (!repo) { | ||
if (await userExists(owner)) { | ||
const rewardData = await calculateOrgReward(owner); | ||
await convertToCSV(rewardData); | ||
} | ||
} else { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
const exists = await checkIfRepoExists(owner, repo); | ||
if (!exists) { | ||
console.log("The repository you have provided does not exist"); | ||
process.exit(); | ||
} | ||
|
||
const issueNumber = Number(process.argv[3]) ?? null; | ||
const rewardData = issueNumber ? await calculateIssueReward(owner, repo, issueNumber) : await calculateRepoReward(owner, repo); | ||
await convertToCSV(rewardData); | ||
} | ||
|
||
const issueNumber = Number(process.argv[3]) ?? null; | ||
const rewardData = issueNumber ? await calculateIssueReward(owner, repo, issueNumber) : await calculateRepoReward(owner, repo); | ||
await convertToCSV(rewardData); | ||
console.log(await userExists(owner)); |