Skip to content
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

feat(platform): getIssue #10453

Merged
merged 4 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 22 additions & 9 deletions lib/platform/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,27 @@ export async function getIssueList(): Promise<Issue[]> {
return config.issueList;
}

export async function getIssue(
number: number,
useCache = true
): Promise<Issue | null> {
try {
const issueBody = (
await githubApi.getJson<{ body: string }>(
`repos/${config.parentRepo || config.repository}/issues/${number}`,
{ useCache }
)
).body.body;
return {
number,
body: issueBody,
};
} catch (err) /* istanbul ignore next */ {
logger.debug({ err, number }, 'Error getting issue');
return null;
}
}

export async function findIssue(title: string): Promise<Issue | null> {
logger.debug(`findIssue(${title})`);
const [issue] = (await getIssueList()).filter(
Expand All @@ -1114,15 +1135,7 @@ export async function findIssue(title: string): Promise<Issue | null> {
return null;
}
logger.debug(`Found issue ${issue.number}`);
const issueBody = (
await githubApi.getJson<{ body: string }>(
`repos/${config.parentRepo || config.repository}/issues/${issue.number}`
)
).body.body;
return {
number: issue.number,
body: issueBody,
};
return getIssue(issue.number);
}

async function closeIssue(issueNumber: number): Promise<void> {
Expand Down
31 changes: 22 additions & 9 deletions lib/platform/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,23 +753,36 @@ export async function getIssueList(): Promise<GitlabIssue[]> {
return config.issueList;
}

export async function findIssue(title: string): Promise<Issue | null> {
logger.debug(`findIssue(${title})`);
export async function getIssue(
number: number,
useCache = true
): Promise<Issue | null> {
try {
const issueList = await getIssueList();
const issue = issueList.find((i) => i.title === title);
if (!issue) {
return null;
}
const issueBody = (
await gitlabApi.getJson<{ description: string }>(
`projects/${config.repository}/issues/${issue.iid}`
`projects/${config.repository}/issues/${number}`,
{ useCache }
)
).body.description;
return {
number: issue.iid,
number,
body: issueBody,
};
} catch (err) /* istanbul ignore next */ {
logger.debug({ err, number }, 'Error getting issue');
return null;
}
}

export async function findIssue(title: string): Promise<Issue | null> {
logger.debug(`findIssue(${title})`);
try {
const issueList = await getIssueList();
const issue = issueList.find((i) => i.title === title);
if (!issue) {
return null;
}
return getIssue(issue.iid);
} catch (err) /* istanbul ignore next */ {
logger.warn('Error finding issue');
return null;
Expand Down
1 change: 1 addition & 0 deletions lib/platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export type EnsureIssueResult = 'updated' | 'created';
export interface Platform {
findIssue(title: string): Promise<Issue | null>;
getIssueList(): Promise<Issue[]>;
getIssue?(number: number, useCache?: boolean): Promise<Issue>;
getVulnerabilityAlerts(): Promise<VulnerabilityAlert[]>;
getRawFile(fileName: string, repo?: string): Promise<string | null>;
getJsonFile(fileName: string, repo?: string): Promise<any | null>;
Expand Down