Skip to content

Commit

Permalink
chore: extract details from Jira
Browse files Browse the repository at this point in the history
  • Loading branch information
RRanath committed Sep 4, 2024
1 parent 93a7d75 commit f2750bf
Showing 1 changed file with 10 additions and 76 deletions.
86 changes: 10 additions & 76 deletions .github/workflows/auto-releast-test.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Auto Release PR

on:
workflow_call:
secrets:
JIRA_AUTH: { required: true }
repository_dispatch:
types: [jira_issue_done]

jobs:
update-auto-release-checkbox:
Expand All @@ -16,76 +15,11 @@ jobs:
- name: Get JIRA Issue Key
id: extract_jira_key
run: |
echo "JIRA_KEY=$(echo "$FEATURE_NAME" | grep -oE 'NDT-[0-9]+')" >> $GITHUB_ENV
- name: Get Issue Status
id: get_status
run: |
response=$(curl -s -X GET \
-H "Authorization: Basic ${{ secrets.JIRA_AUTH }}" \
-H "Content-Type: application/json" \
"https://connectivitydivision.atlassian.net/rest/api/3/issue/$JIRA_KEY")
status=$(echo "$response" | jq -r '.fields.status.name')
echo "Issue status: $status"
echo "::set-output name=status::$status"
- name: Check if PR is up-to-date with main
id: up_to_date
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const baseRef = context.payload.pull_request.base.ref;
const headRef = context.payload.pull_request.head.ref;
const mainCommits = await github.rest.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 25,
sha: baseRef
}).then(response => response.data.map(commit => commit.sha));
const prCommits = await github.rest.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 300,
sha: headRef
}).then(response => response.data.map(commit => commit.sha));
const containsAllCommits = mainCommits.every(commitSHA =>
prCommits.includes(commitSHA)
);
console.log(`PR contains all commits from main branch: ${containsAllCommits}`);
console.log(`Main Commits: ${mainCommits}`);
console.log(`PR Commits: ${prCommits}`);
console.log(`Result: ${containsAllCommits}`);
return containsAllCommits;
- name: Update auto release checkbox
if: steps.get_status.outputs.status == 'MERGE CONFLICT' && steps.up_to_date.outputs.result == true
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
let body = pr.data.body;
const checkboxText = "[ ] Check to trigger automatic release process";
const checkedCheckboxText = "[x] Check to trigger automatic release process";
if (body.includes(checkboxText)) {
body = body.replace(checkboxText, checkedCheckboxText);
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
body: body
});
console.log("Checkbox marked as checked in the PR description.");
} else {
console.log("Checkbox already checked or not found.");
}
echo "Printing JIRA issue key from payload..."
# Check if the JIRA issue key is provided as an input
if [ -z "${{ github.event.client_payload.key }}" ]; then
echo "No issue key found in the payload."
else
echo "JIRA Issue Key: ${{ github.event.client_payload.key }}"
fi

0 comments on commit f2750bf

Please sign in to comment.