Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always create new comments for release #111

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 10 additions & 36 deletions .github/workflows/shared-release-branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
}

// Function to create or update a comment for a pull request (PR) associated with a release
async function createOrUpdateCommentForPR(pr_id, release) {
async function createCommentForPR(pr_id, release) {
// Parameters for fetching comments related to the PR
const parameters = {
owner: context.repo.owner,
Expand All @@ -66,47 +66,21 @@ jobs:
per_page: 100,
}

// Initialize existingComment variable
let existingComment = null;

// Constructing the message to be posted or updated as a comment
const messageId = `<!-- release-pr-comment:${release.id} -->`;
const message = `
${messageId}
These changes were released in [${release.name}](${release.html_url}).
`;

// Iterating through all comments related to the PR
const allComments = github.paginate.iterator(github.rest.issues.listComments, parameters);
for await (comments of allComments) {
// Check if the message id is present in any of the comments
found = comments.data.find(({ body }) => {
return (body?.search(messageId) != -1) > -1;
});

if (found) {
break; // Exit the loop if the comment is found
}
}

// If the comment is found, update it; otherwise, create a new comment
if (found) {
console.log(`Comment found`);
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: found.id,
body: message
});
} else {
console.log(`Comment not found`);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr_id,
body: message
});
}
// Сreate a new comment
console.log(`Comment not found`);
goruha marked this conversation as resolved.
Show resolved Hide resolved
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr_id,
body: message
});
}

// Retrieving the ID of the current release
Expand Down Expand Up @@ -198,6 +172,6 @@ jobs:

// Iterating through unique pull request numbers and creating or updating comments for them
for (id of pull_requests.filter(onlyUnique)) {
await createOrUpdateCommentForPR(id, currentRelease);
await createCommentForPR(id, currentRelease);
}

Loading