Skip to content

Commit 97295c7

Browse files
authored
add action to open PRs for is (#32)
1 parent b094a27 commit 97295c7

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

.github/workflows/create-pr.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Create a PR
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
account:
7+
type: string
8+
default: NODEJS_ORG
9+
action:
10+
type: choice
11+
default: auto
12+
options: [auto, post, repost, reply, quote-post]
13+
description: Type of action you want to perform (you can skip it except for "reply").
14+
postURL:
15+
type: string
16+
description: URL of the POST you'd like to retweet/quote-tweet/reply
17+
required: false
18+
richText:
19+
type: string
20+
description: Content of the post
21+
required: false
22+
prTitle:
23+
type: string
24+
description: Title of the PR and commit message
25+
required: true
26+
prBody:
27+
type: string
28+
description: Body of the PR
29+
required: false
30+
31+
permissions:
32+
contents: write
33+
pull-requests: write
34+
35+
jobs:
36+
process-json:
37+
runs-on: ubuntu-latest
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v4
42+
43+
- name: Guess action
44+
if: inputs.action == 'auto'
45+
id: guess-action
46+
run: |
47+
if [ -n "$POST_URL" ] && [ -n "$RICH_TEXT" ]; then
48+
echo "action=quote-post" >> "$GITHUB_OUTPUT"
49+
elif [ -n "$RICH_TEXT" ]; then
50+
echo "action=post" >> "$GITHUB_OUTPUT"
51+
elif [ -n "$POST_URL" ]; then
52+
echo "action=repost" >> "$GITHUB_OUTPUT"
53+
fi
54+
env:
55+
POST_URL: ${{ inputs.postURL }}
56+
RICH_TEXT: ${{ inputs.richText }}
57+
58+
- name: Write JSON file
59+
run: |
60+
RICH_TEXT_DEFINITION=
61+
if [ -n "$RICH_TEXT" ]; then
62+
printf "%s" "$RICH_TEXT" > records/new/rich.txt
63+
RICH_TEXT_DEFINITION=', richTextFile: "./rich.txt"'
64+
fi
65+
66+
URL_FIELD_DEFINITION=
67+
if [ "$ACTION" = "reply" ]; then
68+
URL_FIELD_DEFINITION=', replyURL: env.URL'
69+
elif [ "$ACTION" = "quote-post" ] || [ "$ACTION" = "repost" ]; then
70+
URL_FIELD_DEFINITION=', repostURL: env.URL'
71+
fi
72+
73+
echo '{}' | jq "{ action: env.ACTION, account: env.ACCOUNT $RICH_TEXT_DEFINITION $URL_FIELD_DEFINITION }" > records/new/new.json
74+
cat records/new/new.json
75+
[ -z "$RICH_TEXT" ] || cat records/new/rich.txt
76+
env:
77+
ACCOUNT: ${{ inputs.account }}
78+
ACTION: ${{ steps.guess-action.outputs.action || inputs.action }}
79+
RICH_TEXT: ${{ inputs.richText }}
80+
URL: ${{ inputs.postURL }}
81+
82+
- name: Create Pull Request
83+
run: |
84+
git config set user.name "$GITHUB_ACTOR"
85+
git config set user.email "[email protected]"
86+
BRANCH_NAME="action/$(node -p 'crypto.randomUUID()')"
87+
git add records/new
88+
git commit -m "$PR_TITLE"
89+
git push origin "HEAD:refs/heads/$BRANCH_NAME"
90+
gh pr create --draft --head "$BRANCH_NAME" --title "$PR_TITLE" --body "$PR_BODY" --assignee "$GITHUB_ACTOR"
91+
env:
92+
GITHUB_TOKEN: ${{ github.token }}
93+
PR_TITLE: ${{ inputs.prTitle }}
94+
PR_BODY: ${{ inputs.prBody }}

.github/workflows/validate.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
pull_request_target:
55
types:
66
- opened
7+
- ready_for_review
8+
- reopened
79
- synchronize
810

911
permissions:

0 commit comments

Comments
 (0)