Skip to content

Commit

Permalink
Merge pull request #1987 from ubiquity/add-pullrequest-scrape
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 authored Dec 16, 2024
2 parents 99c4318 + c5689fa commit 7bc8b6f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/directory/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if (typeof DEVPOOL_OWNER_NAME !== "string" || typeof DEVPOOL_REPO_NAME !== "stri

export type GitHubIssue = RestEndpointMethodTypes["issues"]["get"]["response"]["data"];
export type GitHubLabel = RestEndpointMethodTypes["issues"]["listLabelsOnIssue"]["response"]["data"][0];
export type GitHubPullRequest = RestEndpointMethodTypes["pulls"]["get"]["response"]["data"];

export type StateChanges<T extends string = "open" | "closed"> = {
[key: string]: {
Expand Down
22 changes: 22 additions & 0 deletions src/directory/get-repository-pull-requests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { GitHubPullRequest, octokit } from "./directory";

export async function getRepositoryPullRequests(ownerName: string, repoName: string) {
// Check if the repository is archived
const { data: repo } = await octokit.rest.repos.get({
owner: ownerName,
repo: repoName,
});

if (repo.archived) {
console.warn(`Warning: Repository ${ownerName}/${repoName} is archived. Skipping pull request retrieval.`);
return [];
}

// get all pull requests (opened and closed)
const pullRequests: GitHubPullRequest[] = await octokit.paginate({
method: "GET",
url: `/repos/${ownerName}/${repoName}/pulls`,
});

return pullRequests;
}
10 changes: 9 additions & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue, octokit } from "./directory/directory";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue, GitHubPullRequest, octokit } from "./directory/directory";
import { Statistics } from "./directory/statistics";
let gitChanges: Array<{ path: string; content: string }> = [];

Expand Down Expand Up @@ -121,6 +121,14 @@ export async function commitTasks(tasks: GitHubIssue[]) {
}
}

export async function commitPullRequests(tasks: GitHubPullRequest[]) {
try {
await gitCommit(tasks, "devpool-pull-requests.json");
} catch (error) {
console.error(`Error preparing devpool pull requests for github file: ${error}`);
}
}

export async function commitTwitterMap(twitterMap: TwitterMap) {
try {
await gitCommit(twitterMap, "twitter-map.json");
Expand Down
13 changes: 11 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
import { calculateStatistics } from "./directory/calculate-statistics";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue } from "./directory/directory";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue, GitHubPullRequest } from "./directory/directory";
import { getPartnerUrls as getPartnerRepoUrls } from "./directory/get-partner-urls";
import { getRepoCredentials } from "./directory/get-repo-credentials";
import { getRepositoryIssues } from "./directory/get-repository-issues";
import { getRepositoryPullRequests } from "./directory/get-repository-pull-requests";
import { Statistics } from "./directory/statistics";
import { syncPartnerRepoIssues } from "./directory/sync-partner-repo-issues";
import { commitStatistics, commitTasks } from "./git";
import { commitPullRequests, commitStatistics, commitTasks } from "./git";
import { initializeTwitterMap, TwitterMap } from "./twitter/initialize-twitter-map";

export async function main() {
const twitterMap: TwitterMap = await initializeTwitterMap();
const directoryIssues: GitHubIssue[] = await getRepositoryIssues(DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME);
const partnerRepoUrls = await getPartnerRepoUrls();
const taskList: GitHubIssue[] = [];
const pullRequestList: GitHubPullRequest[] = [];

// for each project URL
for (const partnerRepoUrl of partnerRepoUrls) {
// get owner and repository names from project URL
const result: GitHubIssue[] = await syncPartnerRepoIssues({ partnerRepoUrl, directoryIssues, twitterMap });
taskList.push(...result);

// get all pull requests (opened and closed)
const [ownerName, repoName] = getRepoCredentials(partnerRepoUrl);
const pullRequests: GitHubPullRequest[] = await getRepositoryPullRequests(ownerName, repoName);
pullRequestList.push(...pullRequests);
}

await commitTasks(taskList);
await commitPullRequests(pullRequestList);

// Calculate total rewards from devpool issues
const { rewards, tasks } = await calculateStatistics(await getRepositoryIssues(DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME));
Expand Down

0 comments on commit 7bc8b6f

Please sign in to comment.