Skip to content

Commit

Permalink
gh-actions/github/env/summary: Add PR info
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Northey <ryan@synca.io>
  • Loading branch information
phlax committed Nov 11, 2023
1 parent c4d3809 commit 4508e35
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions gh-actions/github/env/summary/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ inputs:
append:
type: boolean
default: true
base-sha:
type: string
env:
type: string
required: true
Expand All @@ -20,18 +22,27 @@ inputs:
message:
type: string
required: true
pr:
type: number
output-path:
type: string
ref:
type: string
sha:
type: string
required: true
target-branch:
type: string
required: false
title:
type: string
required: true
required: false

outputs:
summary:
value: ${{ steps.output.outputs.string }}
title:
value: ${{ steps.title.outputs.title }}


runs:
Expand All @@ -42,9 +53,13 @@ runs:
with:
string: ${{ inputs.sha }}
length: 7

- uses: envoyproxy/toolshed/gh-actions/str/sub@actions-v0.1.37
id: base-sha-short
with:
string: ${{ inputs.base-sha }}
length: 7
- uses: envoyproxy/toolshed/gh-actions/jq@actions-v0.1.37
name: Change title
name: Change
id: change
with:
input: ${{ inputs.message }}
Expand All @@ -55,6 +70,40 @@ runs:
| {"title": ($message | split("\n")[0]),
"body": ($message | " > " + (split("\n")[1:] | join("\n > ")))}
- run: |
if [[ -n "$TITLE" ]]; then
printf 'title=%s' "${TITLE}" >> "$GITHUB_OUTPUT"
fi
if [[ -n "${{ inputs.link }}" ]]; then
REF_TITLE=(
"${{ ! inputs.pr && 'postsubmit' || 'pr' }}/"
"${{ inputs.target-branch }}"
"@${{ steps.sha-short.outputs.string }}")
else
REF_SHA_LINK="[${{ steps.sha-short.outputs.string }}](https://github.com/${{ github.repository }}/commit/${{ inputs.sha }})"
REF_TITLE=(
"${{ ! inputs.pr && 'postsubmit' || 'pr' }}/"
"${{ inputs.target-branch }}"
"@${REF_SHA_LINK}")
fi
IFS=; echo "title=${REF_TITLE[*]}" >> "$GITHUB_OUTPUT"
shell: bash
id: title
env:
TITLE: ${{ inputs.title }}
- run: |
echo "link=$PR_LINK" >> $GITHUB_OUTPUT
shell: bash
id: pr
if: ${{ inputs.pr }}
env:
PR_LINK: >-
![](https://raw.githubusercontent.com/primer/octicons/main/icons/git-pull-request-16.svg)
[#${{ inputs.pr }}](https://github.com/${{ github.repository }}/pull/${{ inputs.pr }})
[`merge`](https://github.com/${{ github.repository }}/commit/${{ inputs.ref }})
[`${{ inputs.target-branch }}@${{ steps.base-sha-short.outputs.string }}`](https://github.com/${{ github.repository }}/commit/${{ inputs.base-sha }})
- run: |
echo "value<<EOF" >> $GITHUB_OUTPUT
printf "%s\n" "${TITLE}" >> $GITHUB_OUTPUT
Expand All @@ -66,9 +115,9 @@ runs:
TITLE: >-
##
${{ inputs.icon }}
Request (${{ inputs.link && format('[{0}]({1})', inputs.title, inputs.link) || inputs.title }})
Request (${{ inputs.link && format('[{0}]({1})', steps.title.outputs.title, inputs.link) || steps.title.outputs.title }})
BODY: |
<img src="${{ github.event.sender.avatar_url }}" alt="${{ github.actor }}" width="18" height="18"> @${{ github.actor }} [`${{ steps.sha-short.outputs.string }}`](https://github.com/${{ github.repository }}/commit/${{ steps.sha-short.outputs.string }})
<img src="${{ github.event.sender.avatar_url }}" alt="${{ github.actor }}" width="18" height="18"> @${{ github.actor }} [`${{ steps.sha-short.outputs.string }}`](https://github.com/${{ github.repository }}/commit/${{ steps.sha-short.outputs.string }}) ${{ steps.pr.outputs.link }}
<details>
<summary><b>${{ fromJSON(steps.change.outputs.value).title }}</b></summary>
Expand Down

0 comments on commit 4508e35

Please sign in to comment.