Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'pavlovcik/feat/contributor-incentives-t…
Browse files Browse the repository at this point in the history
…otal-scoring' into refactor/type-locations
  • Loading branch information
0x4007 committed Nov 26, 2023
2 parents 5cd3d6d + 5e99029 commit 609b15f
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 267 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
import { Context } from "../../../../types/context";
import { Payload, User } from "../../../../types/payload";
import { User } from "../../../../types/payload";

export async function getCollaboratorsForRepo(context: Context): Promise<User[]> {
const payload = context.event.payload as Payload;
const collaboratorUsers: User[] = [];
const payload = context.payload;

try {
let page = 1;
let shouldFetch = true;

while (shouldFetch) {
const res = await context.event.octokit.rest.repos.listCollaborators({
owner: payload.repository.owner.login,
repo: payload.repository.name,
per_page: 100,
page: page,
});

if (res.data.length > 0) {
res.data.forEach((collaborator) => collaboratorUsers.push(collaborator as User));
page++;
} else {
shouldFetch = false;
}
}
} catch (e: unknown) {
context.logger.error("Fetching collaborator IDs for repo failed!", e);
const collaboratorUsers = (await context.octokit.paginate(context.octokit.rest.repos.listCollaborators, {
owner: payload.repository.owner.login,
repo: payload.repository.name,
per_page: 100,
})) as User[];
return collaboratorUsers;
} catch (err: unknown) {
context.logger.error("Failed to fetch lists of collaborators", err);
return [];
}

return collaboratorUsers;
}
2 changes: 1 addition & 1 deletion src/handlers/comment/handlers/issue/issue-closed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function issueClosed(context: Context) {
return "Please wait until we get the result.";
}

export async function dispatchWorkflow(owner: string, repo: string, workflowId: string, inputs: any) {
async function dispatchWorkflow(owner: string, repo: string, workflowId: string, inputs: any) {
const res = await fetch(`https://api.github.com/repos/${owner}/${repo}/actions/workflows/${workflowId}/dispatches`, {
method: "POST",
headers: {
Expand Down
63 changes: 24 additions & 39 deletions src/handlers/wildcard/unassign/unassign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,56 +311,41 @@ function getActiveAssigneesInDisqualifyDuration(
}

async function getAllEvents({ context, owner, repo, issueNumber }: GetAllEvents) {
let allEvents: IssuesListEventsResponseData = [];
let page = 1;
let events = await context.event.octokit.issues.listEvents({
owner,
repo,
issue_number: issueNumber,
per_page: 100,
page: page,
});

while (events.data.length > 0) {
allEvents = allEvents.concat(events.data.filter(isCorrectType) as IssuesListEventsResponseData);

events = await context.event.octokit.issues.listEvents({
owner,
repo,
issue_number: issueNumber,
per_page: 100,
page: ++page,
});
try {
const events = (await context.octokit.paginate(
context.octokit.rest.issues.listEvents,
{
owner,
repo,
issue_number: issueNumber,
per_page: 100,
},
(response) => response.data.filter((event) => isCorrectType(event as IssuesListEventsResponseData[0]))
)) as IssuesListEventsResponseData;
return events;
} catch (err: unknown) {
context.logger.error("Failed to fetch lists of events", err);
return [];
}
return allEvents;
}

async function getAllCommitsFromPullRequest({ context, owner, repo, pullNumber }: GetAllCommits) {
let allCommits = [] as Commit[];
let commitPage = 1;
let hasMoreCommits = true;

while (hasMoreCommits) {
const commits = await context.event.octokit.pulls.listCommits({
try {
const commits = (await context.octokit.paginate(context.octokit.pulls.listCommits, {
owner,
repo,
pull_number: pullNumber,
per_page: 100,
page: commitPage,
});

if (commits.data.length === 0) {
hasMoreCommits = false;
} else {
allCommits = allCommits.concat(commits.data as Commit[]);
commitPage++;
}
})) as Commit[];
return commits;
} catch (err: unknown) {
context.logger.error("Failed to fetch lists of commits", err);
return [];
}
return allCommits;
}

function isCorrectType(event: any): event is AssignedEvent {
return event && typeof event.id === "number" && event.event === "assigned";
function isCorrectType(event: IssuesListEventsResponseData[0]) {
return event && typeof event.id === "number";
}

interface DisqualifyIdleAssignees {
Expand Down
Loading

0 comments on commit 609b15f

Please sign in to comment.