Skip to content

Commit

Permalink
feat: add partner avatar map
Browse files Browse the repository at this point in the history
  • Loading branch information
zugdev committed Jan 25, 2025
1 parent c9ffe30 commit da89c2b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/directory/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ 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 GitHubOrganization = RestEndpointMethodTypes["orgs"]["get"]["response"]["data"];

export type OrgNameAndAvatarUrl = {
ownerName: string;
avatar_url?: string;
}

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

export async function getPartnerProfilePictures(ownerName: string): Promise<{ownerName: string, avatar_url?: string}> {
const orgResp: GitHubOrganization[] = await octokit.paginate({
method: "GET",
url: `/orgs/${ownerName}`
});

const org = orgResp.find((org) => org.login === ownerName);

return {ownerName, avatar_url: org ? org.avatar_url : undefined};
}
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, GitHubPullRequest, octokit } from "./directory/directory";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue, GitHubPullRequest, octokit, OrgNameAndAvatarUrl } from "./directory/directory";
import { Statistics } from "./directory/statistics";
let gitChanges: Array<{ path: string; content: string }> = [];

Expand Down Expand Up @@ -129,6 +129,14 @@ export async function commitPullRequests(tasks: GitHubPullRequest[]) {
}
}

export async function commitPartnerProfilePictures(tasks: OrgNameAndAvatarUrl[]) {
try {
await gitCommit(tasks, "devpool-partner-profile-pictures.json");
} catch (error) {
console.error(`Error preparing devpool profile pictures for github file: ${error}`);
}
}

export async function commitTwitterMap(twitterMap: TwitterMap) {
try {
await gitCommit(twitterMap, "twitter-map.json");
Expand Down
11 changes: 9 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { calculateStatistics } from "./directory/calculate-statistics";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue, GitHubPullRequest } from "./directory/directory";
import { DEVPOOL_OWNER_NAME, DEVPOOL_REPO_NAME, GitHubIssue, GitHubPullRequest, OrgNameAndAvatarUrl } from "./directory/directory";
import { getPartnerProfilePictures } from "./directory/get-partner-profile-pictures";
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 { commitPullRequests, commitStatistics, commitTasks } from "./git";
import { commitPartnerProfilePictures, commitPullRequests, commitStatistics, commitTasks } from "./git";
import { initializeTwitterMap, TwitterMap } from "./twitter/initialize-twitter-map";

export async function main() {
Expand All @@ -15,6 +16,7 @@ export async function main() {
const partnerRepoUrls = await getPartnerRepoUrls();
const taskList: GitHubIssue[] = [];
const pullRequestList: GitHubPullRequest[] = [];
const partnerProfilePicturesList: OrgNameAndAvatarUrl[] = [];

// for each project URL
for (const partnerRepoUrl of partnerRepoUrls) {
Expand All @@ -26,10 +28,15 @@ export async function main() {
const [ownerName, repoName] = getRepoCredentials(partnerRepoUrl);
const pullRequests: GitHubPullRequest[] = await getRepositoryPullRequests(ownerName, repoName);
pullRequestList.push(...pullRequests);

// get partner profile picture
const org: OrgNameAndAvatarUrl = await getPartnerProfilePictures(ownerName);
partnerProfilePicturesList.push(org);
}

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

// 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 da89c2b

Please sign in to comment.