Skip to content

Commit

Permalink
fix(pingcap/monitoring): no need human approve for the submodule upda…
Browse files Browse the repository at this point in the history
…ting PR (#2824)

Signed-off-by: wuhuizuo <[email protected]>

Signed-off-by: wuhuizuo <[email protected]>
  • Loading branch information
wuhuizuo committed Feb 29, 2024
1 parent 4101faf commit e7af6d3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
4 changes: 4 additions & 0 deletions prow-jobs/pingcap-inc-enterprise-extensions-postsubmits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ postsubmits:
- --base_ref=$(PULL_BASE_REF)
- --sub_ref=$(PULL_BASE_REF)
- --path=pkg/extension/enterprise # new path
- --add_labels=lgtm
- --add_labels=skip-issue-check
env:
- name: GITHUB_API_TOKEN
valueFrom:
Expand Down Expand Up @@ -60,6 +62,8 @@ postsubmits:
- --base_ref=$(PULL_BASE_REF)
- --sub_ref=$(PULL_BASE_REF)
- --path=extension/enterprise # old path
- --add_labels=lgtm
- --add_labels=skip-issue-check
env:
- name: GITHUB_API_TOKEN
valueFrom:
Expand Down
8 changes: 7 additions & 1 deletion prow-jobs/pingcap-ng-monitoring-postsubmits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ postsubmits:
- --sub_repository=$(REPO_NAME)
- --base_ref=$(PULL_BASE_REF)
- --path=ng-monitoring
- --add_labels=lgtm
- --add_labels=approved
- --add_labels=skip-issue-check
env:
- name: GITHUB_API_TOKEN
valueFrom:
Expand All @@ -35,7 +38,7 @@ postsubmits:
memory: 1Gi
requests:
cpu: "1"
memory: 1Gi
memory: 1Gi
- name: update-submodule-release-branches
decorate: true
decoration_config:
Expand All @@ -58,6 +61,9 @@ postsubmits:
- --base_ref=$(PULL_BASE_REF)
- --sub_ref=$(PULL_BASE_REF)
- --path=ng-monitoring
- --add_labels=lgtm
- --add_labels=approved
- --add_labels=skip-issue-check
env:
- name: GITHUB_API_TOKEN
valueFrom:
Expand Down
37 changes: 23 additions & 14 deletions scripts/plugins/update-submodule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface cliArgs {
path: string;
github_private_token: string;
draft: boolean;
add_labels: string[]; // labels to add in post dealing.
}

function newCommitMsg(submodulePath: string) {
Expand Down Expand Up @@ -86,8 +87,14 @@ async function createUpdateSubModulePR(
) {
// Get target branch's git commit SHA.
console.debug("-----");
console.debug(owner, repository, subOwner, subRepository);
console.log(baseRef, subRef);
console.debug({
owner,
repository,
subOwner,
subRepository,
baseRef,
subRef,
});

const { data } = await octokit.rest.git.getRef({
owner,
Expand Down Expand Up @@ -174,6 +181,7 @@ async function postDealPR(
owner: string,
repo: string,
prNumber: number,
toAddLabels: string[],
) {
// add "/release-note-none" comment.
await octokit.rest.issues.createComment({
Expand All @@ -183,17 +191,14 @@ async function postDealPR(
body: "/release-note-none",
}).catch((error: any) => console.error("Error creating comment:", error));

// add "skip-issue-check", "lgtm" labels:
const toAddLabels = ["skip-issue-check", "lgtm"];
if (repo.startsWith("docs")) {
toAddLabels.push("translation/no-need");
if (toAddLabels.length > 0) {
await octokit.rest.issues.addLabels({
owner,
repo,
issue_number: prNumber,
labels: toAddLabels,
}).catch((error: any) => console.error("Error add labels:", error));
}
await octokit.rest.issues.addLabels({
owner,
repo,
issue_number: prNumber,
labels: toAddLabels,
}).catch((error: any) => console.error("Error add labels:", error));
}

// Ref: https://stackoverflow.com/questions/45789854/how-to-update-a-submodule-to-a-specified-commit-via-github-rest-api
Expand All @@ -208,6 +213,7 @@ async function main(args: cliArgs) {
path,
github_private_token,
draft,
add_labels: addLabels,
} = args;
// Create a new Octokit instance using the provided token
const octokit = new Octokit({ auth: github_private_token });
Expand Down Expand Up @@ -239,6 +245,7 @@ async function main(args: cliArgs) {
owner,
repository,
pullRequest.number,
addLabels,
);
console.info(
`✅ Post done for pull request: ${owner}/${repository}/${pullRequest.number} ...`,
Expand All @@ -258,7 +265,9 @@ async function main(args: cliArgs) {
* --path <submodule path in repo>
* --github_private_token <github private token>
* --draft, optional.
* --add_labels <label>
*/
const args = flags.parse<cliArgs>(Deno.args);
const args = flags.parse<cliArgs>(Deno.args, {
collect: ["add_labels"] as never[],
});
await main(args);
Deno.exit(0);

0 comments on commit e7af6d3

Please sign in to comment.