d0321875d9
Signed-off-by: Justin Williams <juwillia@amd.com>
70 satır
2.7 KiB
YAML
70 satır
2.7 KiB
YAML
name: Auto Label PRs
|
|
|
|
on:
|
|
pull_request:
|
|
types: [opened, synchronize, reopened, closed]
|
|
|
|
jobs:
|
|
apply-labels:
|
|
runs-on: AMD-ROCm-Internal-dev1
|
|
permissions:
|
|
pull-requests: write
|
|
steps:
|
|
- name: Add labels based on branch names
|
|
uses: actions/github-script@v6
|
|
with:
|
|
script: |
|
|
const pr = context.payload.pull_request;
|
|
const baseBranch = pr.base.ref;
|
|
const headBranch = pr.head.ref;
|
|
let labelsApplied = false;
|
|
|
|
// Debug information
|
|
console.log(`Processing PR #${pr.number}: Head: ${headBranch}, Base: ${baseBranch}`);
|
|
|
|
// Condition 1: PR targeting amd-mainline
|
|
if (baseBranch === 'amd-mainline') {
|
|
const labelToAdd = 'Merge amd-mainline';
|
|
try {
|
|
await github.rest.issues.addLabels({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: pr.number,
|
|
labels: [labelToAdd]
|
|
});
|
|
console.log(`Added label "${labelToAdd}" to PR #${pr.number}`);
|
|
labelsApplied = true;
|
|
} catch (error) {
|
|
console.error(`Error adding label "${labelToAdd}": ${error.message}`);
|
|
}
|
|
}
|
|
|
|
// Condition 2: Cherry-pick based on head branch name or release target
|
|
const isCherryPickHead = /cherry.*pick/i.test(headBranch);
|
|
const isReleaseTargetBase = baseBranch.startsWith('release/');
|
|
|
|
if (isCherryPickHead || isReleaseTargetBase) {
|
|
const labelToAdd = 'cherry-pick';
|
|
try {
|
|
// Check if the label already exists to avoid redundant API calls if another condition also adds it (though unlikely here)
|
|
const existingLabels = pr.labels.map(label => label.name);
|
|
if (!existingLabels.includes(labelToAdd)) {
|
|
await github.rest.issues.addLabels({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: pr.number,
|
|
labels: [labelToAdd]
|
|
});
|
|
console.log(`Added label "${labelToAdd}" to PR #${pr.number}`);
|
|
labelsApplied = true;
|
|
} else {
|
|
console.log(`Label "${labelToAdd}" already exists on PR #${pr.number}`);
|
|
}
|
|
} catch (error) {
|
|
console.error(`Error adding label "${labelToAdd}": ${error.message}`);
|
|
}
|
|
}
|
|
|
|
if (!labelsApplied) {
|
|
console.log(`PR #${pr.number} did not match criteria for automatic labeling by this workflow.`);
|
|
} |