Repository navigation
144 lines (132 loc) · 7.13 KB
/
Copy pathclassify-issue.yml
File metadata and controls
144 lines (132 loc) · 7.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Labels a new issue from rules (adapted from ArcadeData/arcadedb's classify-issue.yml, minus
# the model call: upstream asks Claude which labels fit, this repository has no API token, so a
# keyword table does it). Only labels that already exist in the repository are applied, and only
# added, never removed, so a person's labels always win. A wrong guess is fixed by hand like any
# label. One issue may get several labels. The groups:
# package jvm, native: the "Package" dropdown of the bug form, else plain words in the title
# or body ("arcadedb-jvm", "JPype", "native build"); an issue opened with
# `gh issue create` or by hand has no dropdown.
# topic vector, performance, concurrency, timeseries: words in the title and body.
# type bug, documentation, enhancement: words in the TITLE only (a body mentions "error"
# or "example" too often to say what the issue is). The issue forms set bug and
# enhancement themselves; this covers the issues they do not.
# language python: Python words in the title or body.
# CI github_actions: CI, workflow and runner words in the title or body.
# `dependencies` is left to Dependabot.
#
# Milestone: a newly opened issue with no milestone gets the open release milestone, chosen as in
# assign-milestone.yml (earliest due date, ties the lower number; no open milestone, nothing is
# set). An existing milestone is never replaced. A dry run logs the milestone it would set.
#
# Try the rules on a real issue without touching it: run the workflow by hand (dry run by default)
# and read the log.
name: Classify issue
on:
issues:
types: [opened]
workflow_dispatch:
inputs:
issue_number:
description: "Issue to classify"
required: true
type: number
dry_run:
description: "If true, log the labels without applying them"
required: false
default: true
type: boolean
permissions:
contents: read
issues: write
jobs:
classify:
# Bots (Dependabot, release automation) open issues that need no triage.
if: github.event_name == 'workflow_dispatch' || github.event.issue.user.type == 'User'
runs-on: ubuntu-latest
steps:
- name: Choose labels from the title and body
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
ISSUE_NUMBER: ${{ github.event.issue.number || inputs.issue_number }}
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run != false }}
with:
script: |
const { owner, repo } = context.repo;
const { data: issue } = await github.rest.issues.get({
owner, repo, issue_number: Number(process.env.ISSUE_NUMBER),
});
const title = issue.title || '';
const body = issue.body || '';
const text = `${title}\n${body}`;
// The value under "### Package" in an issue form's body.
const pkg = (body.match(/### Package\s+([^\n]+)/) || [])[1] || '';
const wanted = new Set();
if (/arcadedb-jvm/i.test(pkg)) wanted.add('jvm');
if (/native/i.test(pkg)) wanted.add('native');
// Without the dropdown: plain words. A title that names a package decides alone ("Native:
// ..." says which build; the body then mentions the other one in passing). Otherwise the
// body counts, but only for a package name or a phrase ("native build", "JPype").
const titleJvm = /\bjvm\b/i.test(title) || /\barcadedb-jvm\b/i.test(title);
const titleNative = /\bnative\b/i.test(title);
if (titleJvm || titleNative) {
if (titleJvm) wanted.add('jvm');
if (titleNative) wanted.add('native');
} else {
if (/\b(arcadedb-jvm|jvm (build|wheel|package)|jpype)\b/i.test(text)) wanted.add('jvm');
if (/\bnative (build|wheel|package)s?\b/i.test(text)) wanted.add('native');
}
// label -> pattern over the title only (the type of the issue)
const titleRules = {
bug: /\b(crash(es|ed)?|died|dies|fail(s|ed|ure|ures)?|errors?|raises?|wrong|regression|returns None|TypeError|exceptions?|hangs?)\b/i,
documentation: /\b(docs?|documentation|pages?|user guide|README|examples?)\b/i,
enhancement: /\b(support for|expose|feature|columnar|facets?|proposal|request)\b|\badd\b.*\boption\b/i,
};
for (const [label, pattern] of Object.entries(titleRules)) {
if (pattern.test(title)) wanted.add(label);
}
// label -> pattern over title and body
const rules = {
python: /\b(python|wheels?|pip|uv add|import arcadedb|pytest|jpype)\b/i,
github_actions: /\b(ci|workflows?|github actions|runners?)\b/i,
vector: /\b(vectors?|jvector|hnsw|embeddings?|find_nearest|knn)\b/i,
performance: /\b(slow|slower|performance|latency|throughput|benchmarks?|speed)\b/i,
concurrency: /\b(threads?|concurrent|concurrency|deadlocks?|race conditions?|locks?)\b/i,
timeseries: /\btime[- ]?series\b/i,
};
for (const [label, pattern] of Object.entries(rules)) {
if (pattern.test(text)) wanted.add(label);
}
// Never invent a label: keep only the ones the repository already has.
const existing = new Set(
(await github.paginate(github.rest.issues.listLabelsForRepo, { owner, repo, per_page: 100 }))
.map(l => l.name),
);
const labels = [...wanted].filter(l => existing.has(l)).sort();
core.info(`#${issue.number} "${title}": package="${pkg}", labels=[${labels.join(', ')}]`);
// The open milestone with the earliest due date (ties: the lower number), as in
// assign-milestone.yml. Only when the issue has none.
let milestone = null;
if (issue.milestone) {
core.info(`#${issue.number}: already in milestone "${issue.milestone.title}".`);
} else {
const open = await github.paginate(github.rest.issues.listMilestones, {
owner, repo, state: 'open', per_page: 100,
});
const byDue = (a, b) =>
(a.due_on ? Date.parse(a.due_on) : Infinity) - (b.due_on ? Date.parse(b.due_on) : Infinity) ||
a.number - b.number;
milestone = open.sort(byDue)[0] || null;
core.info(milestone
? `#${issue.number}: milestone would be "${milestone.title}".`
: 'No open milestone, nothing to assign.');
}
if (process.env.DRY_RUN === 'true') {
core.info('dry run: no label or milestone applied.');
return;
}
if (labels.length > 0) {
await github.rest.issues.addLabels({ owner, repo, issue_number: issue.number, labels });
}
if (milestone) {
await github.rest.issues.update({ owner, repo, issue_number: issue.number, milestone: milestone.number });
}