-
-
Notifications
You must be signed in to change notification settings - Fork 140
130 lines (114 loc) · 5.23 KB
/
issue_bot.yml
File metadata and controls
130 lines (114 loc) · 5.23 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
name: IssueBot
on:
issues:
types: [opened]
permissions:
issues: write
contents: read
jobs:
close_issues:
runs-on: ubuntu-latest
steps:
- name: Process issue
uses: actions/github-script@v6
with:
script: |
const issueBody = context.payload.issue.body;
const issueNumber = context.payload.issue.number;
const currentTitle = context.payload.issue.title;
const issueCreatedAt = new Date(context.payload.issue.created_at);
const templateKeyword = "**Checklist "; // Change this to a unique part of your template
// Define the cutoff date (year, month - 1, day)
const cutoffDate = new Date(2024, 11, 2); // December is month 11 (0-based index)
// Check if the issue was created after the cutoff date
if (issueCreatedAt > cutoffDate) {
// Step 1: Check if the issue body contains the template keyword
if (!issueBody.includes(templateKeyword)) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: "This issue does not follow the template and will be closed. Please update the issue following the template and reopen it."
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: "closed",
state_reason: "not_planned"
});
return; // Exit early if template not followed
}
// Step 2: Generate title if template is followed
try {
const titleResponse = await fetch('https://api.26163212.xyz:5001/generate-title', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
issue_number: issueNumber,
owner: "InfinityLoop1308",
repo: "PipePipe"
})
});
if (!titleResponse.ok) {
throw new Error(`Title generation failed: ${titleResponse.status}`);
}
const titleResult = await titleResponse.json();
console.log(titleResult)
const generatedTitle = titleResult.generated_result;
// Update title if different
if (generatedTitle !== currentTitle) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
title: generatedTitle
});
}
// Step 3: Analyze issue for related issues
const analyzeResponse = await fetch('https://api.26163212.xyz:5001/analyze-issue', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
title: generatedTitle,
owner: "InfinityLoop1308",
repo: "PipePipe"
})
});
if (!analyzeResponse.ok) {
throw new Error(`Issue analysis failed: ${analyzeResponse.status}`);
}
const analyzeResult = await analyzeResponse.json();
console.log(analyzeResult)
const relatedIssues = analyzeResult.related_issues;
// Handle related issues response
if (relatedIssues.length === 0) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: "✅ No similar issues found. This appears to be a unique issue."
});
} else {
const issueLinks = relatedIssues.map(num => `#${num}`).join(', ');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `🔍 Found potentially related issues: ${issueLinks}\n\nPlease check if any of these issues are related to your problem before proceeding.`
});
}
} catch (error) {
console.error('Error processing issue:', error);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: "⚠️ There was an error processing this issue automatically. Please proceed manually."
});
}
}