Skip to content

Commit 5e03714

Browse files
author
NullPointerException
committed
update issue_bot
1 parent 514c423 commit 5e03714

File tree

2 files changed

+128
-47
lines changed

2 files changed

+128
-47
lines changed

.github/workflows/close-issues.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.github/workflows/issue_bot.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: IssueBot
2+
3+
on:
4+
issues:
5+
types: [opened]
6+
7+
permissions:
8+
issues: write
9+
contents: read
10+
11+
jobs:
12+
close_issues:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Process issue
17+
uses: actions/github-script@v6
18+
with:
19+
script: |
20+
const issueBody = context.payload.issue.body;
21+
const issueNumber = context.payload.issue.number;
22+
const currentTitle = context.payload.issue.title;
23+
const issueCreatedAt = new Date(context.payload.issue.created_at);
24+
const templateKeyword = "**Checklist "; // Change this to a unique part of your template
25+
26+
// Define the cutoff date (year, month - 1, day)
27+
const cutoffDate = new Date(2024, 11, 2); // December is month 11 (0-based index)
28+
29+
// Check if the issue was created after the cutoff date
30+
if (issueCreatedAt > cutoffDate) {
31+
// Step 1: Check if the issue body contains the template keyword
32+
if (!issueBody.includes(templateKeyword)) {
33+
await github.rest.issues.createComment({
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
issue_number: issueNumber,
37+
body: "This issue does not follow the template and will be closed. Please update the issue following the template and reopen it."
38+
});
39+
40+
await github.rest.issues.update({
41+
owner: context.repo.owner,
42+
repo: context.repo.repo,
43+
issue_number: issueNumber,
44+
state: "closed",
45+
state_reason: "not_planned"
46+
});
47+
return; // Exit early if template not followed
48+
}
49+
50+
// Step 2: Generate title if template is followed
51+
try {
52+
const titleResponse = await fetch('https://api.26163212.xyz:5001/generate-title', {
53+
method: 'POST',
54+
headers: {
55+
'Content-Type': 'application/json',
56+
},
57+
body: JSON.stringify({
58+
issue_number: issueNumber,
59+
owner: "InfinityLoop1308",
60+
repo: "PipePipe"
61+
})
62+
});
63+
64+
if (!titleResponse.ok) {
65+
throw new Error(`Title generation failed: ${titleResponse.status}`);
66+
}
67+
68+
const titleResult = await titleResponse.json();
69+
const generatedTitle = titleResult.generated_result;
70+
71+
// Update title if different
72+
if (generatedTitle !== currentTitle) {
73+
await github.rest.issues.update({
74+
owner: context.repo.owner,
75+
repo: context.repo.repo,
76+
issue_number: issueNumber,
77+
title: generatedTitle
78+
});
79+
}
80+
81+
// Step 3: Analyze issue for related issues
82+
const analyzeResponse = await fetch('https://api.26163212.xyz:5001/analyze-issue', {
83+
method: 'POST',
84+
headers: {
85+
'Content-Type': 'application/json',
86+
},
87+
body: JSON.stringify({
88+
title: generatedTitle,
89+
owner: "InfinityLoop1308",
90+
repo: "PipePipe"
91+
})
92+
});
93+
94+
if (!analyzeResponse.ok) {
95+
throw new Error(`Issue analysis failed: ${analyzeResponse.status}`);
96+
}
97+
98+
const analyzeResult = await analyzeResponse.json();
99+
const relatedIssues = analyzeResult.related_issues;
100+
101+
// Handle related issues response
102+
if (relatedIssues.length === 0) {
103+
await github.rest.issues.createComment({
104+
owner: context.repo.owner,
105+
repo: context.repo.repo,
106+
issue_number: issueNumber,
107+
body: "✅ No similar issues found. This appears to be a unique issue."
108+
});
109+
} else {
110+
const issueLinks = relatedIssues.map(num => `#${num}`).join(', ');
111+
await github.rest.issues.createComment({
112+
owner: context.repo.owner,
113+
repo: context.repo.repo,
114+
issue_number: issueNumber,
115+
body: `🔍 Found potentially related issues: ${issueLinks}\n\nPlease check if any of these issues are related to your problem before proceeding.`
116+
});
117+
}
118+
119+
} catch (error) {
120+
console.error('Error processing issue:', error);
121+
await github.rest.issues.createComment({
122+
owner: context.repo.owner,
123+
repo: context.repo.repo,
124+
issue_number: issueNumber,
125+
body: "⚠️ There was an error processing this issue automatically. Please proceed manually."
126+
});
127+
}
128+
}

0 commit comments

Comments
 (0)