Skip to content

Commit b40db62

Browse files
authored
Merge pull request #1631 from nscuro/auto-close-non-template-issues
Auto-close issues that do not use an issue template
2 parents dc817b3 + aab9cce commit b40db62

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This file is part of Dependency-Track.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# Copyright (c) OWASP Foundation. All Rights Reserved.
17+
name: Issue Template Check
18+
19+
on:
20+
issues:
21+
types: [ opened ]
22+
23+
permissions: { }
24+
25+
jobs:
26+
validate:
27+
name: Validate Issue Template
28+
runs-on: ubuntu-latest
29+
permissions:
30+
issues: write
31+
steps:
32+
- name: Close issues that bypass templates
33+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
34+
with:
35+
script: |
36+
const issue = context.payload.issue;
37+
38+
if (issue.user.type === 'Bot') {
39+
core.notice(`Skipping bot author '${issue.user.login}'.`);
40+
return;
41+
}
42+
43+
const templateLabels = ['defect', 'in triage', 'enhancement'];
44+
if (issue.labels.some(label => templateLabels.includes(label.name))) {
45+
core.notice('Issue carries template labels; nothing to do.');
46+
return;
47+
}
48+
49+
core.notice(`Closing issue #${issue.number}: opened without an issue template.`);
50+
51+
await github.rest.issues.createComment({
52+
...context.repo,
53+
issue_number: issue.number,
54+
body: [
55+
'This issue was opened without using an issue template, which is only possible when',
56+
'creating issues via the GitHub API. As stated in our',
57+
'[contributing guidelines](https://github.com/DependencyTrack/dependency-track/blob/main/CONTRIBUTING.md#filing-issues),',
58+
'issues that do not use a template will be closed.',
59+
'',
60+
'Please recreate this issue via the',
61+
'[issue chooser](https://github.com/DependencyTrack/frontend/issues/new/choose).',
62+
].join('\n'),
63+
});
64+
65+
await github.rest.issues.update({
66+
...context.repo,
67+
issue_number: issue.number,
68+
state: 'closed',
69+
state_reason: 'not_planned',
70+
});

0 commit comments

Comments
 (0)