Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Use check-labels to label renovate PRs #1197

Merged
merged 10 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
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
49 changes: 49 additions & 0 deletions .github/actions/check-labels/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ async function run() {
const hasMultipleSemverLabels = attachedSemverLabels.length > 1;
const hasOneSemverLabel = attachedSemverLabels.length === 1;
const hasReleaseLabel = labelNames.includes('release');
const userName = pull_request.user.login;

if (userName === 'renovate[bot]') {
if (isMissingSemverLabel) {
const files = await getPullRequestFiles({ octokit });

const isOnlyLockFileChanged = files.every((file) => file.filename.endsWith('package-lock.json'));
if (isOnlyLockFileChanged) {
console.log('Detected renovate PR with only lock file changes. Applying `no-changelog` label.');
await updateLabels({ octokit, labels: ['no-changelog'] });
} else {
console.log('Detected renovate PR with file changes. Applying `patch` label.');
await updateLabels({ octokit, labels: ['patch'] });
}
}
core.setOutput('canMerge', 'Renovate PR');
}

if (isMissingSemverLabel) {
let errorMsg = [
Expand Down Expand Up @@ -91,6 +108,38 @@ async function run() {
}
}

async function getPullRequestFiles({ octokit }) {
const {
payload: { pull_request },
repo,
} = context;
const prNumber = pull_request.number;
const { data } = await octokit.rest.pulls.listFiles({
...repo,
pull_number: prNumber,
});

return data;
}

async function updateLabels({ octokit, labels }) {
try {
const {
payload: { pull_request },
repo,
} = context;
const prNumber = pull_request.number;

await octokit.rest.issues.setLabels({
...repo,
issue_number: prNumber,
labels,
});
} catch (error) {
core.setFailed(error.message);
}
}

async function doComment({ octokit, message }) {
try {
const {
Expand Down
2 changes: 1 addition & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"reviewers": ["team:grafana/plugins-platform-frontend"],
"enabledManagers": ["regex", "npm", "github-actions"],
"postUpdateOptions": ["npmDedupe"],
"labels": ["dependencies", "javascript", "patch"],
"labels": ["dependencies", "javascript"],
// These custom managers are used to bump dependencies in create-plugin template files
"customManagers": [
{
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/check-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
- edited
concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true

permissions:
pull-requests: write
Expand Down
Loading