This is an automated email from the ASF dual-hosted git repository. yihua pushed a commit to branch branch-0.x in repository https://gitbox.apache.org/repos/asf/hudi.git
commit 736ea55ee27cb6feb0bf00da871972e076145e9f Author: Y Ethan Guo <[email protected]> AuthorDate: Tue Feb 27 00:10:31 2024 -0800 [HUDI-7445] Move PR size labeling to GitHub scheduled workflow (#10761) --- .github/workflows/labeler.js | 97 ++++++++++++++++++++++++++++++++ .github/workflows/labeler.yml | 24 -------- .github/workflows/scheduled_workflow.yml | 20 ++++++- 3 files changed, 116 insertions(+), 25 deletions(-) diff --git a/.github/workflows/labeler.js b/.github/workflows/labeler.js new file mode 100644 index 00000000000..77cd48337fb --- /dev/null +++ b/.github/workflows/labeler.js @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +async function labelDocsPr({ github, context, prNumber }) { + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + labels: ['docs'] + }); + + console.log(`- Labeled Docs PR: ${prNumber}`); +} + +async function labelPrWithSize({ github, context, prNumber, prData }) { + console.log(`Label PR based on size: ${prNumber} ${prData.html_url}`); + const additions = prData.additions; + const deletions = prData.deletions; + const totalChanges = additions + deletions; + + let newSizeLabel = ""; + + if (totalChanges <= 10) { + // size:XS : <= 10 LoC + newSizeLabel = "size:XS"; + } else if (totalChanges <= 100) { + // size:S : (10, 100] LoC + newSizeLabel = "size:S"; + } else if (totalChanges <= 300) { + // size:M : (100, 300] LoC + newSizeLabel = "size:M"; + } else if (totalChanges <= 1000) { + // size:L : (300, 1000] LoC + newSizeLabel = "size:L"; + } else { + // size:XL : > 1000 LoC + newSizeLabel = "size:XL"; + } + + // Check existing size label + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber + }); + + const existingSizeLabels = labels.filter(label => label.name.startsWith("size:") && label.name !== newSizeLabel); + const newSizeLabelInExisting = labels.filter(label => label.name === newSizeLabel); + + // Remove stale labels that do not match the new one + for (const label of existingSizeLabels) { + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + name: label.name, + }); + console.log(`Removed stale size label: ${label.name}`); + } + + console.log(`Total lines of changes: ${totalChanges}`); + + // Add the new size label if needed + if (newSizeLabelInExisting.length > 0) { + console.log(`Accurate size Label already exists: ${newSizeLabel}`); + } else { + // Add the new label + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + labels: [newSizeLabel] + }); + console.log(`Added size Label: ${newSizeLabel}`); + } +} + +module.exports = { + labelDocsPr, + labelPrWithSize +}; diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml deleted file mode 100644 index d0b809c2958..00000000000 --- a/.github/workflows/labeler.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Label PR - -on: [ pull_request ] - -jobs: - labeler: - runs-on: ubuntu-latest - name: Label the PR size - steps: - - uses: codelytv/pr-size-labeler@v1 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - xs_label: 'size-xs' - xs_max_size: '10' - s_label: 'size-s' - s_max_size: '100' - m_label: 'size-m' - m_max_size: '500' - l_label: 'size-l' - l_max_size: '1000' - xl_label: 'size-xl' - fail_if_xl: 'false' - github_api_url: 'api.github.com' - files_to_ignore: '' \ No newline at end of file diff --git a/.github/workflows/scheduled_workflow.yml b/.github/workflows/scheduled_workflow.yml index 48fca07ddbb..e6992d6b383 100644 --- a/.github/workflows/scheduled_workflow.yml +++ b/.github/workflows/scheduled_workflow.yml @@ -24,7 +24,7 @@ on: permissions: statuses: write - pull-requests: read + pull-requests: write issues: read jobs: @@ -54,6 +54,7 @@ jobs: per_page: 100 }); + const { labelDocsPr, labelPrWithSize } = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/labeler.js`); const checkAzureCiAndCreateCommitStatus = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/azure_ci.js`); console.log(`Number of PRs to process: ${openPrs.length}`); @@ -70,6 +71,23 @@ jobs: const targetBase = pullRequest.base.ref; console.log(`Target base branch: ${targetBase}`); + // Label docs PR (targeting "asf-site" branch) + if (targetBase === 'asf-site') { + await labelDocsPr({ + github, + context, + prNumber: pr.number + }); + } + + // Label PR size + await labelPrWithSize({ + github, + context, + prNumber: pr.number, + prData: pullRequest + }); + // Check Azure CI and create commit status (targeting "master", "release*", or "branch-0.x" branch) const targetBaseRegex = /^(master|release.*|branch-0\.x)$/; if (targetBaseRegex.test(targetBase)
