Created
September 17, 2024 10:33
-
-
Save conarro/0dd530df0c8d34d1ce175de460e13611 to your computer and use it in GitHub Desktop.
GitHub Pull Request → Campsite Post (via GitHub Actions)
This file contains hidden or 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
name: "🏕️ Campsite" | |
on: | |
pull_request: | |
types: [opened] | |
branches: [ "main" ] | |
jobs: | |
notify-campsite: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Install GitHub CLI | |
run: | | |
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg | |
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null | |
sudo apt update | |
sudo apt install gh | |
- name: Get PR commits and authors | |
id: get-pr-info | |
run: | | |
commits=$(gh pr view ${{ github.event.pull_request.number }} --json commits --jq '.commits[] | "- " + (.messageHeadline | sub("\\n.*"; "")) + " ([" + (.oid | .[0:7]) + "](" + .url + "))"' | jq -Rs .) | |
echo "commits=$commits" >> $GITHUB_OUTPUT | |
authors=$(gh pr view ${{ github.event.pull_request.number }} --json commits --jq '[.commits[].authors[].login] | unique | join(" ")' | tr '[:lower:]' '[:upper:]') | |
mentions="" | |
for author in $authors; do | |
case $author in | |
GH_USERNAME_1) mentions="$mentions <@CAMPSITE_USERNAME_1>";; | |
GH_USERNAME_2) mentions="$mentions <@CAMPSITE_USERNAME_2>";; | |
esac | |
done | |
echo "mentions=$mentions" >> $GITHUB_OUTPUT | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Format contributors | |
id: format-contributors | |
run: | | |
mentions="${{ steps.get-pr-info.outputs.mentions }}" | |
formatted_mentions=$(echo "$mentions" | tr ' ' '\n' | sed '/^$/d; s/^/- /') | |
echo "formatted_mentions<<EOF" >> $GITHUB_OUTPUT | |
echo "$formatted_mentions" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Create Campsite Post | |
uses: campsite/[email protected] | |
with: | |
api_key: ${{ secrets.CAMPSITE_API_KEY }} | |
action_type: create_post | |
title: "New Release: ${{ github.event.pull_request.title }}" | |
content: | | |
A new pull request has been opened targeting `${{ github.base_ref }}`. [View on GitHub →](${{ github.event.pull_request.html_url }}) | |
## Commits in this PR: | |
${{ fromJson(steps.get-pr-info.outputs.commits) }} | |
## Contributors: | |
${{ steps.format-contributors.outputs.formatted_mentions }} | |
channel_id: "CAMPSITE_CHANNEL_ID" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment