Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ”§ Adds label/release config for release notes

Alicia Sykes45599ea67330
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
index a6d00e23..85315bbd 100644
--- a/.github/pull_request_template.md
+++ b/.github/pull_request_template.md
@@ -1,5 +1,5 @@
### Category
-<!-- Bugfix / Feature / Docs / Dependencies / Localization / Widget / Theme / Showcase -->
+<!-- Bugfix / Feature / Docs / Dependencies / Localization / Widget / Theme / Showcase / CI -->
### Overview
<!-- Briefly outline your PR. Explain what was changed and why -->
diff --git a/.github/release.yml b/.github/release.yml
new file mode 100644
index 00000000..7125cf53
--- /dev/null
+++ b/.github/release.yml
@@ -0,0 +1,26 @@
+# Groups merged PRs into sections in the auto-generated release notes,
+# by the category labels applied in .github/workflows/label-pr.yml
+# The first category a PR's labels match wins, so order matters here.
+
+changelog:
+ categories:
+ - title: ✨ New Features
+ labels: ['✨ New Feature']
+ - title: πŸ¦‹ Bug Fixes
+ labels: ['πŸ¦‹ Bug Fix', 'πŸš‘ Hot Fix']
+ - title: πŸ”Œ Widgets
+ labels: ['πŸ”Œ Widget']
+ - title: 🎨 Themes and Styling
+ labels: ['🎨 Theme', 'πŸ’„ Stylistic Changes']
+ - title: 🌐 Localization
+ labels: ['🌐 Language']
+ - title: πŸ’― Showcase
+ labels: ['πŸ’― Showcase']
+ - title: πŸ“• Documentation
+ labels: ['πŸ“• Docs']
+ - title: πŸ› οΈ Build, CI and Refactors
+ labels: ['πŸ› οΈ Build Changes', '🚚 Refactor', 'πŸ—οΈ Architectural Changes']
+ - title: πŸ“¦ Dependencies
+ labels: ['πŸ“¦ Dependencies', 'dependencies']
+ - title: 🌈 Other Changes
+ labels: ['*']
diff --git a/.github/workflows/label-pr.yml b/.github/workflows/label-pr.yml
new file mode 100644
index 00000000..2e586566
--- /dev/null
+++ b/.github/workflows/label-pr.yml
@@ -0,0 +1,70 @@
+# Adds labels to PR based on category or files changed
+# So that release notes can be categorized by change type
+
+name: 🏷️ Label
+
+on:
+ pull_request_target: # zizmor: ignore[dangerous-triggers]
+ types: [opened, edited]
+
+concurrency:
+ group: label-pr-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+
+permissions:
+ contents: read
+ pull-requests: write
+
+jobs:
+ label:
+ name: 🏷️ Apply Category Label
+ runs-on: ubuntu-latest
+ continue-on-error: true
+ steps:
+ - name: Determine and Apply Label
+ uses: actions/github-script@v9
+ with:
+ script: |
+ // [ label, matches Category field, matches changed file paths ]
+ const categories = [
+ ['🌐 Language', /localis|localiz|translat|i18n|language/i, /^src\/assets\/locales\//],
+ ['πŸ”Œ Widget', /widget/i, /^src\/(components|styles)\/[Ww]idgets\/|^docs\/widgets\.md$/],
+ ['🎨 Theme', /theme|theming/i, /^src\/styles\/(themes\/|color-themes\.scss$)|^docs\/theming\.md$/],
+ ['πŸ’― Showcase', /showcase/i, /^docs\/showcase/],
+ ['πŸ“¦ Dependencies', /dependenc|deps/i, /^(yarn\.lock|package\.json)$/],
+ ['πŸ› οΈ Build Changes', /build|\bci\b|workflow/i, /^\.github\/|^Dockerfile$|^vite\.config\.mjs$/],
+ ['πŸ“• Docs', /doc/i, /^docs\/|\.md$/],
+ ['πŸ¦‹ Bug Fix', /bug ?fix|^fix/i, null],
+ ['✨ New Feature', /feature|feat/i, null],
+ ];
+
+ const pr = context.payload.pull_request;
+ const existing = pr.labels.map((l) => l.name);
+ if (categories.some(([label]) => existing.includes(label))) {
+ core.info('PR is already categorised, nothing to do');
+ return;
+ }
+
+ // Read the Category field, ignoring the template's comment hints
+ const body = (pr.body || '').replace(/<!--[\s\S]*?-->/g, '');
+ const stated = (body.match(/#+\s*Category\s*([^\n#]*)/) || ['', ''])[1].trim();
+ let labels = categories.filter(([, field]) => field.test(stated)).map(([label]) => label);
+
+ // If no valid category was given, infer one from the files changed
+ if (!labels.length) {
+ const files = await github.paginate(github.rest.pulls.listFiles, {
+ ...context.repo, pull_number: pr.number, per_page: 100,
+ });
+ const names = files.map((f) => f.filename);
+ const counts = categories.map(([label, , paths]) =>
+ [label, paths ? names.filter((n) => paths.test(n)).length : 0]);
+ const [label, hits] = counts.reduce((a, b) => (b[1] > a[1] ? b : a));
+ if (hits * 2 > names.length) labels = [label];
+ }
+
+ if (!labels.length) {
+ core.info('Unable to determine a category for this PR');
+ return;
+ }
+ await github.rest.issues.addLabels({ ...context.repo, issue_number: pr.number, labels });
+ core.info(`Applied label(s): ${labels.join(', ')}`);