Fix: don't try to migrate cms prs from forks (#3331)
This commit is contained in:
parent
908c42fb58
commit
3e873f3e02
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
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
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
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
@ -361,7 +361,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"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": {
|
"headers": {
|
||||||
"Content-Type": "application/json; charset=utf-8",
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
"Server": "GitHub.com",
|
"Server": "GitHub.com",
|
||||||
|
@ -388,7 +388,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"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": {
|
"headers": {
|
||||||
"Content-Type": "application/json; charset=utf-8",
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
"Server": "GitHub.com",
|
"Server": "GitHub.com",
|
||||||
|
@ -362,7 +362,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"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": {
|
"headers": {
|
||||||
"Content-Type": "application/json; charset=utf-8",
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
"Server": "GitHub.com",
|
"Server": "GitHub.com",
|
||||||
|
@ -388,7 +388,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"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": {
|
"headers": {
|
||||||
"Content-Type": "application/json; charset=utf-8",
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
"Server": "GitHub.com",
|
"Server": "GitHub.com",
|
||||||
|
@ -388,7 +388,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"method": "GET",
|
"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": {
|
"headers": {
|
||||||
"Content-Type": "application/json; charset=utf-8",
|
"Content-Type": "application/json; charset=utf-8",
|
||||||
"Server": "GitHub.com",
|
"Server": "GitHub.com",
|
||||||
|
@ -5,7 +5,7 @@ import { entry1, entry2, entry3 } from './common/entries';
|
|||||||
const backend = 'github';
|
const backend = 'github';
|
||||||
|
|
||||||
describe('Github Backend Editorial Workflow - GraphQL API', () => {
|
describe('Github Backend Editorial Workflow - GraphQL API', () => {
|
||||||
let taskResult = { data: {} };
|
const taskResult = { data: {} };
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
specUtils.before(
|
specUtils.before(
|
||||||
|
@ -5,7 +5,7 @@ import { entry1, entry2, entry3 } from './common/entries';
|
|||||||
const backend = 'github';
|
const backend = 'github';
|
||||||
|
|
||||||
describe('Github Backend Editorial Workflow - GraphQL API - Open Authoring', () => {
|
describe('Github Backend Editorial Workflow - GraphQL API - Open Authoring', () => {
|
||||||
let taskResult = { data: {} };
|
const taskResult = { data: {} };
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
specUtils.before(
|
specUtils.before(
|
||||||
|
@ -5,7 +5,7 @@ import * as specUtils from './common/spec_utils';
|
|||||||
const backend = 'github';
|
const backend = 'github';
|
||||||
|
|
||||||
describe('GitHub Backend Media Library - GraphQL API', () => {
|
describe('GitHub Backend Media Library - GraphQL API', () => {
|
||||||
let taskResult = { data: {} };
|
const taskResult = { data: {} };
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
specUtils.before(
|
specUtils.before(
|
||||||
|
@ -5,7 +5,7 @@ import { entry1, entry2, entry3 } from './common/entries';
|
|||||||
const backend = 'github';
|
const backend = 'github';
|
||||||
|
|
||||||
describe('GitHub Backend Simple Workflow - GraphQL API', () => {
|
describe('GitHub Backend Simple Workflow - GraphQL API', () => {
|
||||||
let taskResult = { data: {} };
|
const taskResult = { data: {} };
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
specUtils.before(
|
specUtils.before(
|
||||||
|
@ -287,7 +287,10 @@ const sanitizeString = (
|
|||||||
.replace(new RegExp(escapeRegExp(owner), 'g'), GITHUB_REPO_OWNER_SANITIZED_VALUE)
|
.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(repo), 'g'), GITHUB_REPO_NAME_SANITIZED_VALUE)
|
||||||
.replace(new RegExp(escapeRegExp(token), 'g'), GITHUB_REPO_TOKEN_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) {
|
if (ownerName) {
|
||||||
replaced = replaced.replace(new RegExp(escapeRegExp(ownerName), 'g'), FAKE_OWNER_USER.name);
|
replaced = replaced.replace(new RegExp(escapeRegExp(ownerName), 'g'), FAKE_OWNER_USER.name);
|
||||||
|
@ -719,6 +719,7 @@ export default class API {
|
|||||||
let metadata = await this.retrieveMetadataOld(contentKey).catch(() => undefined);
|
let metadata = await this.retrieveMetadataOld(contentKey).catch(() => undefined);
|
||||||
|
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
|
console.log(`Skipped migrating Pull Request '${number}' (${countMessage})`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,9 +754,9 @@ export default class API {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCmsBranches() {
|
async getOpenAuthoringBranches() {
|
||||||
const cmsBranches = await this.requestAllPages<Octokit.GitListMatchingRefsResponseItem>(
|
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[]);
|
).catch(() => [] as Octokit.GitListMatchingRefsResponseItem[]);
|
||||||
return cmsBranches;
|
return cmsBranches;
|
||||||
}
|
}
|
||||||
@ -769,7 +770,7 @@ export default class API {
|
|||||||
let branches: string[];
|
let branches: string[];
|
||||||
if (this.useOpenAuthoring) {
|
if (this.useOpenAuthoring) {
|
||||||
// open authoring branches can exist without a pr
|
// 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));
|
branches = cmsBranches.map(b => b.ref.substring('refs/heads/'.length));
|
||||||
// filter irrelevant branches
|
// filter irrelevant branches
|
||||||
const branchesWithFilter = await Promise.all(
|
const branchesWithFilter = await Promise.all(
|
||||||
@ -781,7 +782,7 @@ export default class API {
|
|||||||
const pullRequests = await this.getPullRequests(
|
const pullRequests = await this.getPullRequests(
|
||||||
undefined,
|
undefined,
|
||||||
PullRequestState.Open,
|
PullRequestState.Open,
|
||||||
withoutCmsLabel,
|
pr => !pr.head.repo.fork && withoutCmsLabel(pr),
|
||||||
);
|
);
|
||||||
let prCount = 0;
|
let prCount = 0;
|
||||||
for (const pr of pullRequests) {
|
for (const pr of pullRequests) {
|
||||||
|
@ -62,13 +62,17 @@ type GraphQLPullRequest = {
|
|||||||
title: string;
|
title: string;
|
||||||
mergedAt: string | null;
|
mergedAt: string | null;
|
||||||
labels: { nodes: { name: string }[] };
|
labels: { nodes: { name: string }[] };
|
||||||
|
repository: {
|
||||||
|
id: string;
|
||||||
|
isFork: boolean;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const transformPullRequest = (pr: GraphQLPullRequest) => {
|
const transformPullRequest = (pr: GraphQLPullRequest) => {
|
||||||
return {
|
return {
|
||||||
...pr,
|
...pr,
|
||||||
labels: pr.labels.nodes,
|
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 },
|
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 { repoOwner: owner, repoName: name } = this;
|
||||||
const { data } = await this.query({
|
const { data } = await this.query({
|
||||||
query: queries.cmsBranches,
|
query: queries.openAuthoringBranches,
|
||||||
variables: {
|
variables: {
|
||||||
owner,
|
owner,
|
||||||
name,
|
name,
|
||||||
|
refPrefix: `refs/heads/cms/${this.repo}/`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import gql from 'graphql-tag';
|
|||||||
export const repository = gql`
|
export const repository = gql`
|
||||||
fragment RepositoryParts on Repository {
|
fragment RepositoryParts on Repository {
|
||||||
id
|
id
|
||||||
|
isFork
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
@ -126,11 +126,11 @@ export const branch = gql`
|
|||||||
${fragments.branch}
|
${fragments.branch}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const cmsBranches = gql`
|
export const openAuthoringBranches = gql`
|
||||||
query cmsBranches($owner: String!, $name: String!) {
|
query openAuthoringBranches($owner: String!, $name: String!, $refPrefix: String!) {
|
||||||
repository(owner: $owner, name: $name) {
|
repository(owner: $owner, name: $name) {
|
||||||
...RepositoryParts
|
...RepositoryParts
|
||||||
refs(refPrefix: "refs/heads/cms/", last: 100) {
|
refs(refPrefix: $refPrefix, last: 100) {
|
||||||
nodes {
|
nodes {
|
||||||
...BranchParts
|
...BranchParts
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user