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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 9292 additions and 8472 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -361,7 +361,7 @@
},
{
"method": "GET",
"url": "/repos/forkOwner/repo/git/refs/heads/cms?ts=300",
"url": "/repos/forkOwner/repo/git/refs/heads/cms/forkOwner/repo?ts=300",
"headers": {
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",

View File

@ -388,7 +388,7 @@
},
{
"method": "GET",
"url": "/repos/forkOwner/repo/git/refs/heads/cms?ts=300",
"url": "/repos/forkOwner/repo/git/refs/heads/cms/forkOwner/repo?ts=300",
"headers": {
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",

View File

@ -362,7 +362,7 @@
},
{
"method": "GET",
"url": "/repos/forkOwner/repo/git/refs/heads/cms?ts=300",
"url": "/repos/forkOwner/repo/git/refs/heads/cms/forkOwner/repo?ts=300",
"headers": {
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",

View File

@ -388,7 +388,7 @@
},
{
"method": "GET",
"url": "/repos/forkOwner/repo/git/refs/heads/cms?ts=300",
"url": "/repos/forkOwner/repo/git/refs/heads/cms/forkOwner/repo?ts=300",
"headers": {
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",

View File

@ -388,7 +388,7 @@
},
{
"method": "GET",
"url": "/repos/forkOwner/repo/git/refs/heads/cms?ts=300",
"url": "/repos/forkOwner/repo/git/refs/heads/cms/forkOwner/repo?ts=300",
"headers": {
"Content-Type": "application/json; charset=utf-8",
"Server": "GitHub.com",

View File

@ -5,7 +5,7 @@ import { entry1, entry2, entry3 } from './common/entries';
const backend = 'github';
describe('Github Backend Editorial Workflow - GraphQL API', () => {
let taskResult = { data: {} };
const taskResult = { data: {} };
before(() => {
specUtils.before(

View File

@ -5,7 +5,7 @@ import { entry1, entry2, entry3 } from './common/entries';
const backend = 'github';
describe('Github Backend Editorial Workflow - GraphQL API - Open Authoring', () => {
let taskResult = { data: {} };
const taskResult = { data: {} };
before(() => {
specUtils.before(

View File

@ -5,7 +5,7 @@ import * as specUtils from './common/spec_utils';
const backend = 'github';
describe('GitHub Backend Media Library - GraphQL API', () => {
let taskResult = { data: {} };
const taskResult = { data: {} };
before(() => {
specUtils.before(

View File

@ -5,7 +5,7 @@ import { entry1, entry2, entry3 } from './common/entries';
const backend = 'github';
describe('GitHub Backend Simple Workflow - GraphQL API', () => {
let taskResult = { data: {} };
const taskResult = { data: {} };
before(() => {
specUtils.before(

View File

@ -287,7 +287,10 @@ const sanitizeString = (
.replace(new RegExp(escapeRegExp(owner), 'g'), GITHUB_REPO_OWNER_SANITIZED_VALUE)
.replace(new RegExp(escapeRegExp(repo), 'g'), GITHUB_REPO_NAME_SANITIZED_VALUE)
.replace(new RegExp(escapeRegExp(token), 'g'), GITHUB_REPO_TOKEN_SANITIZED_VALUE)
.replace(new RegExp('https://avatars.+?/u/.+?v=\\d', 'g'), `${FAKE_OWNER_USER.avatar_url}`);
.replace(
new RegExp('https://avatars\\d+\\.githubusercontent\\.com/u/\\d+?\\?v=\\d', 'g'),
`${FAKE_OWNER_USER.avatar_url}`,
);
if (ownerName) {
replaced = replaced.replace(new RegExp(escapeRegExp(ownerName), 'g'), FAKE_OWNER_USER.name);

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
}