diff --git a/src/directory/directory.ts b/src/directory/directory.ts index 3ce9f60e8..d6227863f 100644 --- a/src/directory/directory.ts +++ b/src/directory/directory.ts @@ -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 = { [key: string]: { diff --git a/src/directory/get-partner-profile-pictures.ts b/src/directory/get-partner-profile-pictures.ts new file mode 100644 index 000000000..5082c1095 --- /dev/null +++ b/src/directory/get-partner-profile-pictures.ts @@ -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}; +} diff --git a/src/git.ts b/src/git.ts index 1b601d483..701ea3da6 100644 --- a/src/git.ts +++ b/src/git.ts @@ -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 }> = []; @@ -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"); diff --git a/src/main.ts b/src/main.ts index f291e671d..2f87daa21 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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() { @@ -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) { @@ -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));