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

Feature/linked issue fixes #11

Merged
merged 24 commits into from
Feb 3, 2023
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
7 changes: 5 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async function ensureCorrectLinkingAndEstimates(pullRequest, octokit, isDryRun)
if (!linkedIssue)
return;
const issueGraphqlResponse = await queryZenhubGraphql('getIssueInfo', ZENHUB_ISSUE_ESTIMATE_QUERY, {
repositoryGhId: pullRequestGraphqlResponse.data.data.issueByInfo.repository.ghId,
repositoryGhId: linkedIssue.repo.gh_id,
issueNumber: linkedIssue.number,
workspaceId: consts_1.ZENHUB_WORKSPACE_ID,
});
Expand Down Expand Up @@ -288,7 +288,10 @@ function getLinkedIssue(timelineItems) {
const lastItem = connectPrTimelineItems.pop();
if (!lastItem || lastItem.type === 'issue.disconnect_pr_from_issue')
return;
return lastItem.data.issue;
return {
...lastItem.data.issue,
repo: lastItem.data.issue_repository,
};
}
exports.getLinkedIssue = getLinkedIssue;
;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ describe('ZenHub events extractors', () => {
state: 'open',
title: 'Dependency Dashboard',
number: 493,
repo: {
gh_id: 264953367,
id: 132804227,
name: 'apify-proxy',
},
});
});
test('getLinkedEpics', () => {
Expand Down Expand Up @@ -125,8 +130,9 @@ describe('ZenHub events extractors', () => {
describe('ensureCorrectLinkingAndEstimates', () => {
test('works correctly with a PR', async () => {
const pullRequest = require('./mocks/pull_request.json'); // eslint-disable-line
const octokit = getOctokit('xxx');

await ensureCorrectLinkingAndEstimates(pullRequest, getOctokit('xxx'));
await ensureCorrectLinkingAndEstimates(pullRequest, octokit, false);
});
});
*/
21 changes: 18 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ type PullRequest = components['schemas']['pull-request'];

type OctokitType = ReturnType<typeof getOctokit>;

type ZenhubRepo = {
id: number,
name: string,
gh_id: number,
};

type ZenhubIssue = {
id: number,
type: string,
Expand All @@ -24,13 +30,19 @@ type ZenhubIssue = {
number: number,
}

type ZenhubIssueWithRepo = ZenhubIssue & {
repo: ZenhubRepo,
}

export type ZenhubTimelineItem = {
id: string,
type: string,
createdAt: Date,
issue: object,
data: {
issue: ZenhubIssue,
repository: ZenhubRepo,
issue_repository: ZenhubRepo,
},
};

Expand Down Expand Up @@ -238,7 +250,7 @@ export async function ensureCorrectLinkingAndEstimates(pullRequest: PullRequest,
if (!linkedIssue) return;

const issueGraphqlResponse = await queryZenhubGraphql('getIssueInfo', ZENHUB_ISSUE_ESTIMATE_QUERY, {
repositoryGhId: pullRequestGraphqlResponse.data.data.issueByInfo.repository.ghId,
repositoryGhId: linkedIssue.repo.gh_id,
issueNumber: linkedIssue.number,
workspaceId: ZENHUB_WORKSPACE_ID,
});
Expand Down Expand Up @@ -270,7 +282,7 @@ export async function fail(pullRequest: PullRequest, errorMessage: string, octok
/**
* Processes a track record of ZenHub events for a PR and returns an issue that is currently linked to the PR.
*/
export function getLinkedIssue(timelineItems: ZenhubTimelineItem[]): ZenhubIssue | undefined {
export function getLinkedIssue(timelineItems: ZenhubTimelineItem[]): ZenhubIssueWithRepo | undefined {
const connectPrTimelineItems = timelineItems.filter(
(item) => ['issue.disconnect_pr_from_issue', 'issue.connect_pr_to_issue'].includes(item.type),
);
Expand All @@ -279,7 +291,10 @@ export function getLinkedIssue(timelineItems: ZenhubTimelineItem[]): ZenhubIssue
const lastItem = connectPrTimelineItems.pop();
if (!lastItem || lastItem.type as string === 'issue.disconnect_pr_from_issue') return;

return lastItem.data.issue;
return {
...lastItem.data.issue,
repo: lastItem.data.issue_repository,
};
};

/**
Expand Down