Skip to content

Commit aca8c97

Browse files
Copilotdanroth27
andcommitted
Add comprehensive error handling and fix escaping issues
Co-authored-by: danroth27 <1874516+danroth27@users.noreply.github.com>
1 parent fec8b17 commit aca8c97

File tree

1 file changed

+66
-42
lines changed

1 file changed

+66
-42
lines changed

.github/workflows/create-docs-issue.yaml

Lines changed: 66 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,45 +37,60 @@ jobs:
3737
3838
// Check if we've already created a docs issue for this breaking change
3939
// First, check for existing comments in the current issue
40-
const comments = await github.rest.issues.listComments({
41-
owner: context.repo.owner,
42-
repo: context.repo.repo,
43-
issue_number: issueNumber
44-
});
45-
46-
const commentExists = comments.data.some(comment =>
47-
comment.body.includes('A documentation tracking issue has been created')
48-
);
49-
50-
if (commentExists) {
51-
console.log('Docs issue comment already exists. Skipping.');
52-
return;
40+
let commentExists = false;
41+
try {
42+
const comments = await github.rest.issues.listComments({
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
issue_number: issueNumber
46+
});
47+
48+
commentExists = comments.data.some(comment =>
49+
comment.body.includes('A documentation tracking issue has been created')
50+
);
51+
52+
if (commentExists) {
53+
console.log('Docs issue comment already exists. Skipping.');
54+
return;
55+
}
56+
} catch (error) {
57+
console.warn('Failed to fetch comments, proceeding with search-based duplicate detection:', error);
58+
// Continue with search-based duplicate detection
5359
}
5460
5561
// Also check the docs repository for existing issues with the same title
5662
// Use a more robust search that can handle special characters
5763
const docsIssueTitle = `[Breaking Change] ${issueTitle}`;
58-
const escapedTitle = docsIssueTitle.replace(/"/g, '\\"');
59-
const searchResults = await github.rest.search.issuesAndPullRequests({
60-
q: `"${escapedTitle}" repo:dotnet/AspNetCore.Docs is:issue in:title`
61-
});
64+
// Properly escape double quotes for use in search query
65+
const escapedTitle = docsIssueTitle.replace(/"/g, '\\\\"');
6266
63-
if (searchResults.data.total_count > 0) {
64-
console.log('Docs issue already exists in target repository. Skipping.');
65-
// Add comment to the original issue with link to existing docs issue if not already present
66-
const existingDocsIssue = searchResults.data.items[0];
67-
try {
68-
await github.rest.issues.createComment({
69-
owner: context.repo.owner,
70-
repo: context.repo.repo,
71-
issue_number: issueNumber,
72-
body: `📝 A documentation tracking issue has been created: ${existingDocsIssue.html_url}`
73-
});
74-
} catch (commentError) {
75-
console.error('Failed to post comment about existing docs issue:', commentError);
76-
// Don't fail the workflow if we can't post the comment
67+
try {
68+
const searchResults = await github.rest.search.issuesAndPullRequests({
69+
q: `"${escapedTitle}" repo:dotnet/AspNetCore.Docs is:issue in:title`
70+
});
71+
72+
if (searchResults.data.total_count > 0) {
73+
console.log('Docs issue already exists in target repository.');
74+
const existingDocsIssue = searchResults.data.items[0];
75+
76+
// Try to add a comment with link to existing docs issue
77+
try {
78+
await github.rest.issues.createComment({
79+
owner: context.repo.owner,
80+
repo: context.repo.repo,
81+
issue_number: issueNumber,
82+
body: `📝 A documentation tracking issue has been created: ${existingDocsIssue.html_url}`
83+
});
84+
console.log('Added comment linking to existing docs issue.');
85+
} catch (commentError) {
86+
console.error('Failed to post comment about existing docs issue:', commentError);
87+
// Don't fail the workflow if we can't post the comment
88+
}
89+
return;
7790
}
78-
return;
91+
} catch (searchError) {
92+
console.warn('Search for existing docs issues failed, proceeding with issue creation:', searchError);
93+
// If search fails, proceed with creating the issue to avoid missing documentation
7994
}
8095
8196
// Create the issue body for the docs repo
@@ -94,24 +109,17 @@ ${issueBody}
94109
Please add documentation for this breaking change to the ASP.NET Core documentation.`;
95110

96111
// Create the issue in dotnet/aspnetcore.docs
112+
let newIssue;
97113
try {
98-
const newIssue = await github.rest.issues.create({
114+
newIssue = await github.rest.issues.create({
99115
owner: 'dotnet',
100116
repo: 'AspNetCore.Docs',
101117
title: `[Breaking Change] ${issueTitle}`,
102118
body: docsIssueBody,
103119
labels: ['breaking-change', 'aspnet/Announcements']
104120
});
105121

106-
console.log(`Created issue: ${newIssue.data.html_url}`);
107-
108-
// Comment on the original issue with a link to the docs issue
109-
await github.rest.issues.createComment({
110-
owner: context.repo.owner,
111-
repo: context.repo.repo,
112-
issue_number: issueNumber,
113-
body: `📝 A documentation tracking issue has been created: ${newIssue.data.html_url}`
114-
});
122+
console.log(`Created docs issue: ${newIssue.data.html_url}`);
115123
} catch (error) {
116124
console.error('Error creating docs issue:', error);
117125
// Check if error is due to missing token permissions
@@ -120,3 +128,19 @@ Please add documentation for this breaking change to the ASP.NET Core documentat
120128
}
121129
throw new Error(`Failed to create docs issue: ${error.message}`);
122130
}
131+
132+
// Comment on the original issue with a link to the docs issue
133+
// This is in a separate try-catch so the workflow doesn't fail if commenting fails
134+
try {
135+
await github.rest.issues.createComment({
136+
owner: context.repo.owner,
137+
repo: context.repo.repo,
138+
issue_number: issueNumber,
139+
body: `📝 A documentation tracking issue has been created: ${newIssue.data.html_url}`
140+
});
141+
console.log('Added comment to original issue.');
142+
} catch (commentError) {
143+
console.error('Failed to post comment on original issue:', commentError);
144+
// Don't fail the workflow - the docs issue was created successfully
145+
console.log(`Docs issue created successfully at ${newIssue.data.html_url} but failed to comment on source issue.`);
146+
}

0 commit comments

Comments
 (0)