-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Extract job ID from saucelabs (#3698)
* TASK: Extract job ID from saucelabs * TASK: Use script to comment the PR * TASK: Install gh cli * TASK: Fix indention * BUGFIX: Adjust pathes * TASK: Update comments when we have new recordings * BUGFIX: Use all job IDs from the e2e step * TASK: Remove debug messages and readd saucelabs test * TASK: Rename job
- Loading branch information
1 parent
b34d35b
commit 7031363
Showing
2 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/bin/bash | ||
|
||
# Check if the required parameters are provided | ||
if [ $# -ne 2 ]; then | ||
echo "Usage: $0 <JobID> <PullRequestNumber>" | ||
exit 1 | ||
fi | ||
|
||
# If no comment with recordings exists, create a new comment | ||
# create a function names createNewComment with the comment body as parameter | ||
|
||
function generateCommentBody() { | ||
# Split the JobID string into an array | ||
IFS=$'\n' read -r -d '' -a jobIdArray <<< "$jobIds" | ||
echo "Generate comment message for following JobIDs: ${jobIdArray[@]}" | ||
|
||
# Iterate over each JobID in the array | ||
for i in ${!jobIdArray[@]}; do | ||
iterator=$(($i+1)) | ||
jobId="${jobIdArray[$i]}" | ||
link="[Recording $iterator](https://app.saucelabs.com/rest/v1/jobs/$jobId/video.mp4)" | ||
videoRecordingsLinks+="\n* $link" | ||
done | ||
|
||
# Construct the comment with the latest acceptance test recordings | ||
# Construct the comment with the latest acceptance test recordings | ||
if [ -n "$videoRecordingsLinks" ]; then | ||
commentBody="🎥 **End-to-End Test Recordings**\n\n$videoRecordingsLinks\n\nThese videos demonstrate the end-to-end tests for the changes in this pull request." | ||
else | ||
# empty comment body to prevent a comment without recordings | ||
commentBody="" | ||
fi | ||
} | ||
|
||
# Check if a comment with recordings already exists | ||
function getExistingComment() { | ||
echo "Checking if a comment with recordings already exists..." | ||
existingComment=$(gh pr view --repo neos/neos-ui $pullRequestNumber --json comments | jq -r ".comments[] | select( .body | contains(\"End-to-End Test Recordings\"))") | ||
} | ||
|
||
function createComment() { | ||
echo "Creating new comment..." | ||
gh pr comment --repo neos/neos-ui $pullRequestNumber --body "$(printf "$commentBody")" | ||
} | ||
|
||
# If a comment with recordings exists, update the existing comment | ||
function updateComment() { | ||
# Note: The gh cli does not support editing comments yet, so we have to use the GitHub API directly | ||
echo "Updating existing comment..." | ||
commentUri=$(echo "$existingComment" | jq -r ".url") | ||
commentId=$(echo "$commentUri" | awk -F'#issuecomment-' '{print $2}') | ||
jsonBody=$(jq -n --arg str "$(printf "$commentBody")" '{"body": $str}') | ||
|
||
curl -s -H "Authorization: token $GH_TOKEN" \ | ||
-X PATCH -d "$jsonBody" \ | ||
"https://api.github.com/repos/neos/neos-ui/issues/comments/$commentId" | ||
} | ||
|
||
jobIds=$1 | ||
pullRequestNumber=$2 | ||
generateCommentBody | ||
getExistingComment | ||
|
||
echo "Existing comment: $existingComment" | ||
if [ -n "$existingComment" ]; then | ||
updateComment | ||
else | ||
createComment | ||
fi | ||
|
||
echo "Comment added to Pull Request #$pullRequestNumber with the latest acceptance test recordings." |