Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(github): Add "sourceRepo" field for created PRs (#7347)
  • Loading branch information
zharinov committed Sep 22, 2020
1 parent 4e5a94c commit feadc14
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
18 changes: 18 additions & 0 deletions lib/platform/github/__snapshots__/index.spec.ts.snap
Expand Up @@ -111,8 +111,14 @@ Array [
exports[`platform/github createPr() should create a draftPR if set in the settings 1`] = `
Object {
"displayNumber": "Pull Request #123",
"head": Object {
"repo": Object {
"full_name": "some/repo",
},
},
"number": 123,
"sourceBranch": "some-branch",
"sourceRepo": "some/repo",
}
`;

Expand Down Expand Up @@ -173,8 +179,14 @@ Array [
exports[`platform/github createPr() should create and return a PR object 1`] = `
Object {
"displayNumber": "Pull Request #123",
"head": Object {
"repo": Object {
"full_name": "some/repo",
},
},
"number": 123,
"sourceBranch": "some-branch",
"sourceRepo": "some/repo",
}
`;

Expand Down Expand Up @@ -249,8 +261,14 @@ Array [
exports[`platform/github createPr() should use defaultBranch 1`] = `
Object {
"displayNumber": "Pull Request #123",
"head": Object {
"repo": Object {
"full_name": "some/repo",
},
},
"number": 123,
"sourceBranch": "some-branch",
"sourceRepo": "some/repo",
}
`;

Expand Down
3 changes: 3 additions & 0 deletions lib/platform/github/index.spec.ts
Expand Up @@ -1598,6 +1598,7 @@ describe('platform/github', () => {
.post('/repos/some/repo/pulls')
.reply(200, {
number: 123,
head: { repo: { full_name: 'some/repo' } },
})
.post('/repos/some/repo/issues/123/labels')
.reply(200, []);
Expand All @@ -1617,6 +1618,7 @@ describe('platform/github', () => {
initRepoMock(scope, 'some/repo');
scope.post('/repos/some/repo/pulls').reply(200, {
number: 123,
head: { repo: { full_name: 'some/repo' } },
});
await github.initRepo({ repository: 'some/repo', token: 'token' } as any);
const pr = await github.createPr({
Expand All @@ -1634,6 +1636,7 @@ describe('platform/github', () => {
initRepoMock(scope, 'some/repo');
scope.post('/repos/some/repo/pulls').reply(200, {
number: 123,
head: { repo: { full_name: 'some/repo' } },
});
await github.initRepo({ repository: 'some/repo', token: 'token' } as any);
const pr = await github.createPr({
Expand Down
9 changes: 4 additions & 5 deletions lib/platform/github/index.ts
Expand Up @@ -49,8 +49,6 @@ import {
Comment,
GhBranchStatus,
GhGraphQlPr,
GhPr,
GhPulls,
GhRepo,
GhRestPr,
LocalRepoConfig,
Expand Down Expand Up @@ -694,10 +692,10 @@ export async function getPrList(): Promise<Pr[]> {
logger.trace('getPrList()');
if (!config.prList) {
logger.debug('Retrieving PR list');
let prList: GhPulls;
let prList: GhRestPr[];
try {
prList = (
await githubApi.getJson<GhPulls>(
await githubApi.getJson<GhRestPr[]>(
`repos/${
config.parentRepo || config.repository
}/pulls?per_page=100&state=all`,
Expand Down Expand Up @@ -1389,7 +1387,7 @@ export async function createPr({
}
logger.debug({ title, head, base, draft: draftPR }, 'Creating PR');
const pr = (
await githubApi.postJson<GhPr>(
await githubApi.postJson<GhRestPr>(
`repos/${config.parentRepo || config.repository}/pulls`,
options
)
Expand All @@ -1404,6 +1402,7 @@ export async function createPr({
}
pr.displayNumber = `Pull Request #${pr.number}`;
pr.sourceBranch = sourceBranch;
pr.sourceRepo = pr.head.repo.full_name;
await addLabels(pr.number, labels);
return pr;
}
Expand Down
28 changes: 12 additions & 16 deletions lib/platform/github/types.ts
Expand Up @@ -26,8 +26,19 @@ export interface GhPr extends Pr {
}

export interface GhRestPr extends GhPr {
head: { ref: string; sha: string };
head: {
ref: string;
sha: string;
repo: { full_name: string };
};
mergeable_state: string;
number: number;
title: string;
state: string;
merged_at: string;
created_at: string;
closed_at: string;
user?: { login?: string };
}

export interface GhGraphQlPr extends GhPr {
Expand Down Expand Up @@ -81,18 +92,3 @@ export interface GhRepo {
};
};
}

export type GhPulls = {
number: number;
head: {
ref: string;
sha: string;
repo: { full_name: string };
};
title: string;
state: string;
merged_at: string;
created_at: string;
closed_at: string;
user?: { login?: string };
}[];

0 comments on commit feadc14

Please sign in to comment.