Merge pull request #7306 from BlueWallet/eeoe

OPS: Delete previous "APK available" comments
This commit is contained in:
GLaDOS 2024-11-18 10:22:20 +00:00 committed by GitHub
commit f7e7d67d76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -90,7 +90,6 @@ platform :android do
end
end
desc "Upload APK to BrowserStack and post result as PR comment"
lane :upload_to_browserstack_and_comment do
Dir.chdir(project_root) do
@ -120,8 +119,10 @@ platform :android do
browserstack_hashed_id = app_url.gsub('bs://', '')
pr_number = ENV['GITHUB_PR_NUMBER']
comment_identifier = '### APK Successfully Uploaded to BrowserStack'
comment = <<~COMMENT
### APK Successfully Uploaded to BrowserStack
#{comment_identifier}
You can test it on the following devices:
@ -139,11 +140,39 @@ platform :android do
**BrowserStack App URL**: #{app_url}
COMMENT
# Post PR comment if PR number is available
# Delete Previous BrowserStack Comments
if pr_number
begin
sh("GH_TOKEN=#{ENV['GH_TOKEN']} gh pr comment #{pr_number} --body '#{comment}'")
UI.success("Posted comment to PR ##{pr_number}")
repo = ENV['GITHUB_REPOSITORY'] # Format: "owner/repo"
repo_owner, repo_name = repo.split('/')
UI.message("Fetching existing comments for PR ##{pr_number}...")
comments_json = `gh api -X GET /repos/#{repo_owner}/#{repo_name}/issues/#{pr_number}/comments`
comments = JSON.parse(comments_json)
comments.each do |comment|
if comment['body'].start_with?(comment_identifier)
comment_id = comment['id']
UI.message("Deleting previous comment ID: #{comment_id}...")
`gh api -X DELETE /repos/#{repo_owner}/#{repo_name}/issues/comments/#{comment_id}`
UI.success("Deleted comment ID: #{comment_id}")
end
end
rescue => e
UI.error("Failed to delete previous comments: #{e.message}")
end
else
UI.important("No PR number found. Skipping deletion of previous comments.")
end
# Post New Comment to PR
if pr_number
begin
escaped_comment = comment.gsub("'", "'\\''")
sh("GH_TOKEN=#{ENV['GH_TOKEN']} gh pr comment #{pr_number} --body '#{escaped_comment}'")
UI.success("Posted new comment to PR ##{pr_number}")
rescue => e
UI.error("Failed to post comment to PR: #{e.message}")
end
@ -153,7 +182,6 @@ platform :android do
end
end
end
# ===========================
# iOS Lanes
@ -412,7 +440,7 @@ lane :build_app_lane do
end
end
end
end
# ===========================
# Global Lanes
# ===========================