Fix: don't try to migrate cms prs from forks (#3331)

This commit is contained in:
Erez Rokah
2020-02-27 18:24:39 +01:00
committed by GitHub
parent 908c42fb58
commit 3e873f3e02
42 changed files with 9292 additions and 8472 deletions

View File

@ -719,6 +719,7 @@ export default class API {
let metadata = await this.retrieveMetadataOld(contentKey).catch(() => undefined);
if (!metadata) {
console.log(`Skipped migrating Pull Request '${number}' (${countMessage})`);
return;
}
@ -753,9 +754,9 @@ export default class API {
);
}
async getCmsBranches() {
async getOpenAuthoringBranches() {
const cmsBranches = await this.requestAllPages<Octokit.GitListMatchingRefsResponseItem>(
`${this.repoURL}/git/refs/heads/cms`,
`${this.repoURL}/git/refs/heads/cms/${this.repo}`,
).catch(() => [] as Octokit.GitListMatchingRefsResponseItem[]);
return cmsBranches;
}
@ -769,7 +770,7 @@ export default class API {
let branches: string[];
if (this.useOpenAuthoring) {
// open authoring branches can exist without a pr
const cmsBranches: Octokit.GitListMatchingRefsResponse = await this.getCmsBranches();
const cmsBranches: Octokit.GitListMatchingRefsResponse = await this.getOpenAuthoringBranches();
branches = cmsBranches.map(b => b.ref.substring('refs/heads/'.length));
// filter irrelevant branches
const branchesWithFilter = await Promise.all(
@ -781,7 +782,7 @@ export default class API {
const pullRequests = await this.getPullRequests(
undefined,
PullRequestState.Open,
withoutCmsLabel,
pr => !pr.head.repo.fork && withoutCmsLabel(pr),
);
let prCount = 0;
for (const pr of pullRequests) {

View File

@ -62,13 +62,17 @@ type GraphQLPullRequest = {
title: string;
mergedAt: string | null;
labels: { nodes: { name: string }[] };
repository: {
id: string;
isFork: boolean;
};
};
const transformPullRequest = (pr: GraphQLPullRequest) => {
return {
...pr,
labels: pr.labels.nodes,
head: { ref: pr.headRefName, sha: pr.headRefOid },
head: { ref: pr.headRefName, sha: pr.headRefOid, repo: { fork: pr.repository.isFork } },
base: { ref: pr.baseRefName, sha: pr.baseRefOid },
};
};
@ -266,13 +270,14 @@ export default class GraphQLAPI extends API {
);
}
async getCmsBranches() {
async getOpenAuthoringBranches() {
const { repoOwner: owner, repoName: name } = this;
const { data } = await this.query({
query: queries.cmsBranches,
query: queries.openAuthoringBranches,
variables: {
owner,
name,
refPrefix: `refs/heads/cms/${this.repo}/`,
},
});

View File

@ -3,6 +3,7 @@ import gql from 'graphql-tag';
export const repository = gql`
fragment RepositoryParts on Repository {
id
isFork
}
`;

View File

@ -126,11 +126,11 @@ export const branch = gql`
${fragments.branch}
`;
export const cmsBranches = gql`
query cmsBranches($owner: String!, $name: String!) {
export const openAuthoringBranches = gql`
query openAuthoringBranches($owner: String!, $name: String!, $refPrefix: String!) {
repository(owner: $owner, name: $name) {
...RepositoryParts
refs(refPrefix: "refs/heads/cms/", last: 100) {
refs(refPrefix: $refPrefix, last: 100) {
nodes {
...BranchParts
}