label-issue-product.yml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. name: Label issue product
  2. on:
  3. issues:
  4. types: [opened, edited]
  5. permissions:
  6. issues: write
  7. concurrency:
  8. group: issue-product-${{ github.event.issue.number }}
  9. cancel-in-progress: false
  10. jobs:
  11. label-product:
  12. runs-on: ubuntu-latest
  13. timeout-minutes: 5
  14. if: ${{ github.repository == 'MiniMax-AI/minimax-code' && github.event.repository.private == false && !github.event.issue.pull_request }}
  15. steps:
  16. - name: Synchronize product labels
  17. env:
  18. GH_TOKEN: ${{ github.token }}
  19. shell: bash
  20. run: |
  21. node <<'EOF'
  22. const fs = require('node:fs');
  23. async function main() {
  24. const event = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8'));
  25. const issuePath = `/repos/${process.env.GITHUB_REPOSITORY}/issues/${event.issue.number}`;
  26. async function request(path, method = 'GET', body) {
  27. const response = await fetch(`${process.env.GITHUB_API_URL}${path}`, {
  28. method,
  29. headers: {
  30. Authorization: `Bearer ${process.env.GH_TOKEN}`,
  31. Accept: 'application/vnd.github+json',
  32. 'Content-Type': 'application/json',
  33. },
  34. body: body === undefined ? undefined : JSON.stringify(body),
  35. });
  36. if (!response.ok) throw new Error(`GitHub ${method} failed: ${response.status}`);
  37. return response.status === 204 ? undefined : response.json();
  38. }
  39. // Read current state so queued edits cannot restore an outdated label.
  40. const issue = await request(issuePath);
  41. const body = (issue.body || '').replace(/\r\n/g, '\n');
  42. const product = body.match(/^### Product or interface\n+([^\n]+)\n*(?=### |$)/m)?.[1].trim();
  43. const products = new Map([
  44. ['Desktop app', 'desktop'],
  45. ['CLI - interactive TUI', 'tui'],
  46. ['CLI - headless', null],
  47. ['CLI - ACP', null],
  48. ['Source build or repository tooling', null],
  49. ]);
  50. // Leave manually triaged issues alone when no valid form answer exists.
  51. if (!products.has(product)) return;
  52. const desired = products.get(product);
  53. const labels = issue.labels.map(label => label.name);
  54. if (desired && !labels.includes(desired)) {
  55. await request(`${issuePath}/labels`, 'POST', { labels: [desired] });
  56. }
  57. for (const label of ['desktop', 'tui']) {
  58. if (label !== desired && labels.includes(label)) {
  59. await request(`${issuePath}/labels/${label}`, 'DELETE');
  60. }
  61. }
  62. }
  63. main();
  64. EOF