Skip to content

Commit d47ff86

Browse files
author
NullPointerException
committed
update issue_bot
1 parent d186ea2 commit d47ff86

File tree

1 file changed

+94
-4
lines changed

1 file changed

+94
-4
lines changed

.github/workflows/issue_bot.yml

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ name: IssueBot
33
on:
44
issues:
55
types: [opened]
6+
workflow_dispatch:
7+
inputs:
8+
issue_number:
9+
description: 'Issue number to process'
10+
required: true
11+
type: string
612

713
permissions:
814
issues: write
@@ -17,15 +23,99 @@ jobs:
1723
uses: actions/github-script@v6
1824
with:
1925
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);
26+
let issueNumber;
27+
let issueBody;
28+
let currentTitle;
29+
let issueCreatedAt;
30+
let isManualTrigger = false;
31+
32+
// Check if this is a manual trigger or automatic
33+
if (context.eventName === 'workflow_dispatch') {
34+
isManualTrigger = true;
35+
issueNumber = parseInt(context.payload.inputs.issue_number);
36+
37+
// Fetch issue details for manual trigger
38+
const issue = await github.rest.issues.get({
39+
owner: context.repo.owner,
40+
repo: context.repo.repo,
41+
issue_number: issueNumber
42+
});
43+
44+
issueBody = issue.data.body;
45+
currentTitle = issue.data.title;
46+
issueCreatedAt = new Date(issue.data.created_at);
47+
} else {
48+
// Automatic trigger from issue creation
49+
issueBody = context.payload.issue.body;
50+
issueNumber = context.payload.issue.number;
51+
currentTitle = context.payload.issue.title;
52+
issueCreatedAt = new Date(context.payload.issue.created_at);
53+
}
54+
2455
const templateKeyword = "**Checklist "; // Change this to a unique part of your template
2556
2657
// Define the cutoff date (year, month - 1, day)
2758
const cutoffDate = new Date(2024, 11, 2); // December is month 11 (0-based index)
2859
60+
// For manual trigger, only regenerate title
61+
if (isManualTrigger) {
62+
try {
63+
const titleResponse = await fetch('https://api.26163212.xyz:5001/generate-title', {
64+
method: 'POST',
65+
headers: {
66+
'Content-Type': 'application/json',
67+
},
68+
body: JSON.stringify({
69+
issue_number: issueNumber,
70+
repo: "InfinityLoop1308/PipePipe"
71+
})
72+
});
73+
74+
if (!titleResponse.ok) {
75+
throw new Error(`Title generation failed: ${titleResponse.status}`);
76+
}
77+
78+
const titleResult = await titleResponse.json();
79+
console.log(titleResult);
80+
81+
const generatedTitle = titleResult.generated_result;
82+
83+
// Update title if different
84+
if (generatedTitle !== currentTitle) {
85+
await github.rest.issues.update({
86+
owner: context.repo.owner,
87+
repo: context.repo.repo,
88+
issue_number: issueNumber,
89+
title: generatedTitle
90+
});
91+
92+
await github.rest.issues.createComment({
93+
owner: context.repo.owner,
94+
repo: context.repo.repo,
95+
issue_number: issueNumber,
96+
body: `🔄 Title updated from manual trigger:\nOld: "${currentTitle}"\nNew: "${generatedTitle}"`
97+
});
98+
} else {
99+
await github.rest.issues.createComment({
100+
owner: context.repo.owner,
101+
repo: context.repo.repo,
102+
issue_number: issueNumber,
103+
body: "✅ Manual title regeneration completed. No changes needed."
104+
});
105+
}
106+
107+
} catch (error) {
108+
console.error('Error processing manual trigger:', error);
109+
await github.rest.issues.createComment({
110+
owner: context.repo.owner,
111+
repo: context.repo.repo,
112+
issue_number: issueNumber,
113+
body: "⚠️ There was an error processing the manual title regeneration."
114+
});
115+
}
116+
return; // Exit early for manual trigger
117+
}
118+
29119
// Check if the issue was created after the cutoff date
30120
if (issueCreatedAt > cutoffDate) {
31121
// Step 1: Check if the issue body contains the template keyword

0 commit comments

Comments
 (0)