Skip to content

Makes octokit milestone aware #52

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

Merged
merged 2 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,23 @@ export interface Issue {
isPr: boolean;
numComments: number;
reactions: Reactions;
milestoneId: number | null;
milestone: Milestone | null;
assignee?: string;
assignees: string[];
createdAt: number;
updatedAt: number;
closedAt?: number;
}
export interface Milestone {
milestoneId: number;
title: string;
description: string;
numClosedIssues: number;
numOpenIssues: number;
dueOn: string;
createdAt: string;
closedAt: string;
}
export interface Query {
q: string;
sort?: SortVar;
Expand Down
16 changes: 14 additions & 2 deletions api/octokit.js

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

17 changes: 15 additions & 2 deletions api/octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GitHub as GitHubAPI } from '@actions/github';
import { Octokit } from '@octokit/rest';
import { exec } from 'child_process';
import { safeLog } from '../common/utils';
import { Comment, GitHub, GitHubIssue, Issue, Query, User } from './api';
import { Comment, GitHub, GitHubIssue, Issue, Milestone, Query, User } from './api';

let numRequests = 0;
export const getNumRequests = () => numRequests;
Expand Down Expand Up @@ -91,13 +91,26 @@ export class OctoKit implements GitHub {
assignee: issue.assignee?.login ?? (issue as Octokit.IssuesGetResponse).assignees?.[0]?.login,
assignees:
(issue as Octokit.IssuesGetResponse).assignees?.map((assignee) => assignee.login) ?? [],
milestoneId: issue.milestone?.number ?? null,
milestone: issue.milestone ? this.octokitMilestoneToMilestone(issue.milestone) : null,
createdAt: +new Date(issue.created_at),
updatedAt: +new Date(issue.updated_at),
closedAt: issue.closed_at ? +new Date(issue.closed_at as unknown as string) : undefined,
};
}

protected octokitMilestoneToMilestone(milestone: Octokit.IssuesGetResponseMilestone): Milestone {
return {
title: milestone.title,
closedAt: milestone.closed_at,
dueOn: milestone.due_on,
milestoneId: milestone.id,
createdAt: milestone.created_at,
description: milestone.description,
numClosedIssues: milestone.closed_issues,
numOpenIssues: milestone.open_issues,
};
}

private writeAccessCache: Record<string, boolean> = {};
async hasWriteAccess(user: User): Promise<boolean> {
if (user.name in this.writeAccessCache) {
Expand Down
16 changes: 15 additions & 1 deletion api/testbed.js

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

15 changes: 14 additions & 1 deletion api/testbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,20 @@ export class TestbedIssue extends Testbed implements GitHubIssue {
}

async setMilestone(milestoneId: number): Promise<void> {
this.issueConfig.issue.milestoneId = milestoneId;
if (this.issueConfig.issue.milestone) {
this.issueConfig.issue.milestone.milestoneId = milestoneId;
} else {
this.issueConfig.issue.milestone = {
milestoneId,
title: '',
description: '',
dueOn: '',
closedAt: '',
createdAt: '',
numClosedIssues: 0,
numOpenIssues: 0,
};
}
}

async getIssue(): Promise<Issue> {
Expand Down
9 changes: 6 additions & 3 deletions feature-request/FeatureRequest.js

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

6 changes: 3 additions & 3 deletions feature-request/FeatureRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class FeatureRequestQueryer {
const issueData = await issue.getIssue();
if (
issueData.open &&
issueData.milestoneId === this.config.milestones.candidateID &&
issueData.milestone?.milestoneId === this.config.milestones.candidateID &&
issueData.labels.includes(this.config.featureRequestLabel) &&
!issueData.labels.some((issueLabel) =>
this.config.labelsToExclude.some((excludeLabel) => issueLabel === excludeLabel),
Expand Down Expand Up @@ -128,7 +128,7 @@ export class FeatureRequestOnLabel {

if (
!issue.open ||
issue.milestoneId ||
issue.milestone?.milestoneId ||
!issue.labels.includes(this.label) ||
(await this.github.hasWriteAccess(issue.author))
) {
Expand All @@ -144,7 +144,7 @@ export class FeatureRequestOnMilestone {

async run(): Promise<void> {
const issue = await this.github.getIssue();
if (issue.open && issue.milestoneId === this.milestone) {
if (issue.open && issue.milestone?.milestoneId === this.milestone) {
await this.github.postComment(CREATE_MARKER + '\n' + this.comment);
}
}
Expand Down