forked from OpenLiberty/liberty-tools-intellij
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from vaisakhkannan/Issue-45-Lsp4ij-Workitem-2
Issue 45 lsp4ij workitem 2
- Loading branch information
Showing
3 changed files
with
284 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
name: Fetch All Open Pull Requests using condition | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: '**' | ||
pull_request: | ||
branches: [ main, code-action-unification, issue-45-main ] | ||
|
||
jobs: | ||
fetch_all_pull_requests_and_notify_using_condition: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Restore cache | ||
id: cache-restore | ||
uses: actions/cache@v2 | ||
with: | ||
path: cache | ||
key: ${{ runner.os }}-pr-cache-${{ github.run_id }} | ||
restore-keys: | | ||
${{ runner.os }}-pr-cache | ||
- name: Check if cache restored | ||
run: | | ||
if [ -f cache/notified_prs.json ]; then | ||
echo "Cache restored successfully." | ||
cat cache/notified_prs.json | ||
else | ||
echo "Cache not restored or file does not exist." | ||
fi | ||
- name: Fetch all opened pull request details using condition | ||
id: fetch_all_pull_requests_using_condition | ||
run: | | ||
mkdir -p cache | ||
pr_infos=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
"https://api.github.com/repos/vaisakhkannan/liberty-tools-intellij/pulls?state=open&sort=created&direction=desc&per_page=100") | ||
echo "API Data ------$pr_infos" | ||
# Load previous PR data if exists | ||
if [ -f cache/notified_prs.json ]; then | ||
previous_prs=$(cat cache/notified_prs.json) | ||
echo "Previous PRs -------$previous_prs" | ||
else | ||
previous_prs="[]" | ||
fi | ||
pr_list="" | ||
new_notified_prs="[]" | ||
notify=false | ||
for pr_info in $(echo "$pr_infos" | jq -r '.[] | @base64'); do | ||
_jq() { | ||
echo "$pr_info" | base64 --decode | jq -r "${1}" | ||
} | ||
pr_number=$(_jq '.number') | ||
pr_title=$(_jq '.title') | ||
pr_user=$(_jq '.user.login') | ||
pr_url=$(_jq '.html_url') | ||
pr_draft=$(_jq '.draft') | ||
pr_created_at=$(_jq '.created_at') | ||
pr_updated_at=$(_jq '.updated_at') | ||
pr_data=$(jq -n --arg number "$pr_number" --arg updated_at "$pr_updated_at" '{number: $number, updated_at: $updated_at}') | ||
new_notified_prs=$(echo "$new_notified_prs" | jq --argjson pr_data "$pr_data" '. += [$pr_data]') | ||
echo "Whole PR data ------- $pr_data" | ||
echo "New Notified PR List------ $new_notified_prs" | ||
# Check if the PR is new or updated | ||
previous_pr=$(echo "$previous_prs" | jq --arg number "$pr_number" '.[] | select(.number == $number)') | ||
echo "Checking PR is new or not --- $previous_pr" | ||
if [ -z "$previous_pr" ] || [ "$(echo "$previous_pr" | jq -r '.updated_at')" != "$pr_updated_at" ]; then | ||
pr_list="${pr_list}\n*Pull Request* #${pr_number}: ${pr_title}\n*Created by*: ${pr_user}\n*URL*: ${pr_url}\n*Draft*: ${pr_draft}\n*Created At*: ${pr_created_at}\n*Last Updated At*: ${pr_updated_at}\n" | ||
echo "New PR List ------- $pr_list" | ||
notify=true | ||
echo "Boolean Value for notify ------- $notify" | ||
fi | ||
done | ||
# Save current PR data for future comparison | ||
echo "$new_notified_prs" > cache/notified_prs.json | ||
echo "Latest Modified ------" | ||
cat cache/notified_prs.json # Ensure the JSON file is updated and print its content for debugging | ||
if [ "$notify" = true ]; then | ||
echo -e "$pr_list" > pr_list.txt | ||
echo "::set-output name=notify::true" | ||
else | ||
echo "::set-output name=notify::false" | ||
fi | ||
- name: Debug Notify Value | ||
run: | | ||
echo "Notify value: ${{ steps.fetch_all_pull_requests_using_condition.outputs.notify }}" | ||
- name: Send Slack notification | ||
if: success() && steps.fetch_all_pull_requests_using_condition.outputs.notify == 'true' | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
run: | | ||
echo "Condition value ------: ${{ steps.fetch_all_pull_requests_using_condition.outputs.notify }}" | ||
pr_list=$(cat pr_list.txt) | ||
payload=$(cat <<-EOF | ||
{ | ||
"blocks": [ | ||
{ | ||
"type": "header", | ||
"text": { | ||
"type": "plain_text", | ||
"text": "List of Open Pull Requests using condition latest 4" | ||
} | ||
}, | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": "${pr_list}" | ||
} | ||
} | ||
] | ||
} | ||
EOF | ||
) | ||
echo "$payload" # Debugging: Print payload to verify its formatt | ||
curl -X POST -H 'Content-type: application/json' --data "$payload" $SLACK_WEBHOOK_URL || echo "Slack notification failed with status code: $?" | ||
- name: Save cache | ||
if: always() | ||
uses: actions/cache@v2 | ||
with: | ||
path: cache | ||
key: ${{ runner.os }}-pr-cache-${{ github.run_id }} | ||
|
||
- name: Verify Cache Save | ||
if: always() | ||
run: | | ||
echo "Checking saved cache content..." | ||
ls -l cache/ | ||
cat cache/notified_prs.json |
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,67 @@ | ||
name: Cron Job to List All Open Pull Requests | ||
|
||
on: | ||
schedule: | ||
- cron: '30 6 * * 1-5' | ||
|
||
jobs: | ||
fetch_all_pull_requests_and_notify_cron_job: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Fetch all opened pull request details using cron jobs | ||
shell: bash | ||
id: fetch_all_pull_requests_using_cron | ||
run: | | ||
pr_infos=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
"https://api.github.com/repos/redhat-developer/lsp4ij/pulls?state=open&sort=created&direction=desc&per_page=100") | ||
pr_list="" | ||
for pr_info in $(echo "$pr_infos" | jq -r '.[] | @base64'); do | ||
_jq() { | ||
echo "$pr_info" | base64 --decode | jq -r "${1}" | ||
} | ||
pr_number=$(_jq '.number') | ||
pr_title=$(_jq '.title') | ||
pr_user=$(_jq '.user.login') | ||
pr_url=$(_jq '.html_url') | ||
pr_draft=$(_jq '.draft') | ||
pr_created_at=$(_jq '.created_at') | ||
pr_updated_at=$(_jq '.updated_at') | ||
pr_list="${pr_list}\n*Pull Request* #${pr_number}: ${pr_title}\n*Created by*: ${pr_user}\n*URL*: ${pr_url}\n*Draft*: ${pr_draft}\n*Created At*: ${pr_created_at}\n*Last Updated At*: ${pr_updated_at}\n" | ||
done | ||
echo -e "$pr_list" > pr_list.txt | ||
cat pr_list.txt | ||
- name: Send Slack notification | ||
if: success() | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
run: | | ||
pr_list=$(cat pr_list.txt) | ||
payload=$(cat <<-EOF | ||
{ | ||
"blocks": [ | ||
{ | ||
"type": "header", | ||
"text": { | ||
"type": "plain_text", | ||
"text": "List of Open Pull Requests using Cron Jobs" | ||
} | ||
}, | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": "${pr_list}" | ||
} | ||
} | ||
] | ||
} | ||
EOF | ||
) | ||
echo "$payload" | ||
curl -X POST -H 'Content-type: application/json' --data "$payload" $SLACK_WEBHOOK_URL |
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,70 @@ | ||
name: Fetch All Open Pull Requests | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: '**' | ||
pull_request: | ||
branches: [ main, code-action-unification, issue-45-main ] | ||
|
||
jobs: | ||
fetch_all_pull_requests_and_notify: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Fetch all opened pull request details | ||
shell: bash | ||
id: fetch_all_pull_requests | ||
run: | | ||
pr_infos=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
"https://api.github.com/repos/redhat-developer/lsp4ij/pulls?state=open&sort=created&direction=desc&per_page=100") | ||
pr_list="" | ||
for pr_info in $(echo "$pr_infos" | jq -r '.[] | @base64'); do | ||
_jq() { | ||
echo "$pr_info" | base64 --decode | jq -r "${1}" | ||
} | ||
pr_number=$(_jq '.number') | ||
pr_title=$(_jq '.title') | ||
pr_user=$(_jq '.user.login') | ||
pr_url=$(_jq '.html_url') | ||
pr_draft=$(_jq '.draft') | ||
pr_created_at=$(_jq '.created_at') | ||
pr_updated_at=$(_jq '.updated_at') | ||
pr_list="${pr_list}\n*Pull Request* #${pr_number}: ${pr_title}\n*Created by*: ${pr_user}\n*URL*: ${pr_url}\n*Draft*: ${pr_draft}\n*Created At*: ${pr_created_at}\n*Last Updated At*: ${pr_updated_at}\n" | ||
done | ||
echo -e "$pr_list" > pr_list.txt | ||
cat pr_list.txt | ||
- name: Send Slack notification | ||
if: success() | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
run: | | ||
pr_list=$(cat pr_list.txt) | ||
payload=$(cat <<-EOF | ||
{ | ||
"blocks": [ | ||
{ | ||
"type": "header", | ||
"text": { | ||
"type": "plain_text", | ||
"text": "List of Open Pull Requests" | ||
} | ||
}, | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": "${pr_list}" | ||
} | ||
} | ||
] | ||
} | ||
EOF | ||
) | ||
echo "$payload" | ||
curl -X POST -H 'Content-type: application/json' --data "$payload" $SLACK_WEBHOOK_URL |