How to change URLs in all comments to pull requests in our GitHub project

Viewed 54

Our Jenkins server has moved to a different data center, and its DNS name has changed. All links to previous builds and logs files, recorded in pull requests comments in our GitHub projects, have suddenly become stale.

Is there a way to automatically edit all PR comments, and replace the old DNS name by the new one in the links, to make these links valid again?

1 Answers

For existing PR comment, the (assuming here) GitHub CLI does not seem to expose the feature of editing existing comment.

gh pr comment would only create new PR comments.

You might need to use the GitHub API Update a review comment for a pull request

patch /repos/{owner}/{repo}/pulls/comments/{comment_id}

Which supposed in your case to list comments first.


For existing commit messages which would include Jenkins URLs, you would need to:

  • clone locally repository
  • rewrite the commit messages
  • force push everything (git push --mirror)

Make sure your collaborators re-clone the new history.

To change to commit messages, use newren/git-filter-repo (python-based, to be installed first)

Updating commit/tag messages

If you want to modify commit or tag messages, you can do so with the same syntax as --replace-text, explained above.

For example, with a file named expressions.txt containing

foo==>bar

then running

git filter-repo --replace-message expressions.txt

will replace foo in commit or tag messages with bar.

Related