Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map upwork data #45100

Merged
merged 14 commits into from
Oct 2, 2024
Merged
Next Next commit
Make the same files without crazy git diff
  • Loading branch information
roryabraham committed Jul 7, 2023
commit 3e9270b7ebc438ba15497a946ac0b5105d7e5cc3
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"concurrently": "^5.3.0",
"copy-webpack-plugin": "^6.4.1",
"css-loader": "^6.7.2",
"csv-writer": "^1.6.0",
"diff-so-fancy": "^1.3.0",
"dotenv": "^16.0.3",
"electron": "22.3.14",
Expand Down
105 changes: 105 additions & 0 deletions scripts/AggregateGitHubDataFromUpwork.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* To run this script from the root of E/App:
*
* node ./scripts/AggregateGitHubDataFromUpwork.js <path_to_csv> <github_pat>
*/

/* eslint-disable no-console, @lwc/lwc/no-async-await, no-restricted-syntax, no-await-in-loop */
const _ = require('underscore');
const fs = require('fs');
const {GitHub, getOctokitOptions} = require('@actions/github/lib/utils');
const {throttling} = require('@octokit/plugin-throttling');
const {paginateRest} = require('@octokit/plugin-paginate-rest');
const createCsvWriter = require('csv-writer').createObjectCsvWriter;

const csvWriter = createCsvWriter({
path: 'output.csv',
header: [
{id: 'number', title: 'number'},
{id: 'title', title: 'title'},
{id: 'labels', title: 'labels'},
{id: 'type', title: 'type'},
],
});

if (process.argv.length < 3) {
throw new Error('Error: must provide filepath for CSV data');
}

if (process.argv.length < 4) {
throw new Error('Error: must provide GitHub token');
}

// Get filepath for csv
const filepath = process.argv[2];

// Get data from csv
let issues = _.filter(fs.readFileSync(filepath).toString().split('\n'), (issue) => !_.isEmpty(issue));

// Skip header row
issues = issues.slice(1);

// Get GitHub token
const token = process.argv[3].trim();
const Octokit = GitHub.plugin(throttling, paginateRest);
const octokit = new Octokit(
getOctokitOptions(token, {
throttle: {
onRateLimit: (retryAfter, options) => {
console.warn(`Request quota exhausted for request ${options.method} ${options.url}`);

// Retry once after hitting a rate limit error, then give up
if (options.request.retryCount <= 1) {
console.log(`Retrying after ${retryAfter} seconds!`);
return true;
}
},
onAbuseLimit: (retryAfter, options) => {
// does not retry, only logs a warning
console.warn(`Abuse detected for request ${options.method} ${options.url}`);
},
},
}),
).rest;

function getType(labels) {
if (_.contains(labels, 'Bug')) {
return 'bug';
}
if (_.contains(labels, 'NewFeature')) {
return 'feature';
}
return 'other';
}

async function getGitHubData() {
const gitHubData = [];
for (const issueNumber of issues) {
const num = issueNumber.trim();
console.info(`Fetching ${num}`);
const result = await octokit.issues
.get({
owner: 'Expensify',
repo: 'App',
issue_number: num,
})
.catch(() => {
console.warn(`Error getting issue ${num}`);
});
if (result) {
const issue = result.data;
const labels = _.map(issue.labels, (label) => label.name);
gitHubData.push({
number: issue.number,
title: issue.title,
labels,
type: getType(labels),
});
}
}
return gitHubData;
}

getGitHubData()
.then((gitHubData) => csvWriter.writeRecords(gitHubData))
.then(() => console.info('Done ✅ Wrote file to output.csv'));