Skip to content
Merged
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
68 changes: 30 additions & 38 deletions GithubCommentReader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,43 +243,6 @@ async function triggerGHActionWithComment(request, event, payload, message) {
});
}

/**
* @param {*} request
* @param {string} targetBranch
* @param {boolean} produceLKG
* @param {(s: string) => void} log
*/
async function makeCherryPickPR(request, targetBranch, produceLKG, log) {
const cli = getGHClient();
const pr = (await cli.pulls.get({ pull_number: request.issue.number, owner: "microsoft", repo: "TypeScript" })).data;
try {
await cli.git.getRef({
owner: "Microsoft",
repo: "TypeScript",
ref: `heads/${targetBranch}`
});
}
catch (_) {
const requestingUser = request.comment.user.login;
await cli.issues.createComment({
body: `Heya @${requestingUser}, I couldn't find the branch '${targetBranch}' on Microsoft/TypeScript. You may need to make it and try again.`,
issue_number: pr.number,
owner: "Microsoft",
repo: "TypeScript"
});
return;
}
await makeNewBuildWithComments(request, `task to cherry-pick this into \`${targetBranch}\``, 30, log, p => ({
...p,
sourceBranch: `refs/pull/${pr.number}/head`,
parameters: JSON.stringify({
...JSON.parse(p.parameters),
target_branch: targetBranch,
...(produceLKG ? {PRODUCE_LKG: "true"} : {})
})
}));
}

/**
* @typedef {Object} CommentAction
* @property {(req: any, log: (s: string) => void, match: RegExpExecArray) => Promise<void>} task
Expand Down Expand Up @@ -415,7 +378,36 @@ const commands = (/** @type {Map<RegExp, CommentAction>} */(new Map()))
})
};
})))
.set(/cherry-?pick (?:this )?(?:in)?to (\S+)( and LKG)?/, action(async (request, log, match) => await makeCherryPickPR(request, match[1], !!match[2], log)))
.set(/cherry-?pick (?:this )?(?:in)?to (\S+)?/, action(async (request, log, match) => {
const targetBranch = match[1];
const requestingUser = request.comment.user.login;

const cli = getGHClient();
const pr = (await cli.pulls.get({ pull_number: request.issue.number, owner: "microsoft", repo: "TypeScript" })).data;
try {
await cli.git.getRef({
owner: "Microsoft",
repo: "TypeScript",
ref: `heads/${targetBranch}`
});
}
catch (_) {
const requestingUser = request.comment.user.login;
await cli.issues.createComment({
body: `Heya @${requestingUser}, I couldn't find the branch '${targetBranch}' on Microsoft/TypeScript. You may need to make it and try again.`,
issue_number: pr.number,
owner: "Microsoft",
repo: "TypeScript"
});
return;
}

await triggerGHActionWithComment(request, "create-cherry-pick-pr", {
pr: request.issue.number,
target_branch: targetBranch,
requesting_user: requestingUser,
}, `cherry-pick this into \`${targetBranch}\``);
}))
.set(/create release-([\d\.]+)/, action(async (request, log, match) => {
const cli = getGHClient();
const targetBranch = `release-${match[1]}`;
Expand Down