This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
131 lines (118 loc) · 5.79 KB
/
git-command.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: "/git command"
on:
repository_dispatch:
types: [ git-command ]
concurrency:
group: ${{ github.workflow }}-${{ github.event.client_payload.github.payload.issue.number }}-${{ github.event.client_payload.slash_command.command }}-${{ github.event.client_payload.slash_command.args.unnamed.arg1 || github.event.client_payload.slash_command.args.all }}
jobs:
merge:
if: ${{ github.event.client_payload.slash_command.args.unnamed.arg1 == 'merge' }}
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: hmarr/debug-action@v3.0.0
- name: Add Workflow link to command comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
- name: Checkout on chat command
uses: actions/checkout@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.ref }}
submodules: 'recursive'
fetch-depth: 0
- name: Configure git
shell: bash
run: |
set -xeuo pipefail
git config --global user.name '${{ github.event.client_payload.github.actor }}'
git config --global user.email '${{ github.event.client_payload.github.actor }}@users.noreply.github.com'
- name: Check for merge conflict
id: check-conflict
env:
SLASH_COMMAND_ARG_BRANCH: ${{ github.event.client_payload.slash_command.args.unnamed.arg2 }}
shell: bash
run: |
set -xeuo pipefail
echo "merge_conflict=$(git merge-tree $(git merge-base HEAD origin/$SLASH_COMMAND_ARG_BRANCH) origin/$SLASH_COMMAND_ARG_BRANCH HEAD | grep '<<')" >> $GITHUB_OUTPUT
- name: Add reaction to command comment on merge conflict
uses: peter-evans/create-or-update-comment@v4
if: ${{ steps.check-conflict.outputs.merge_conflict }}
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> **Error**: Merge conflict detected, please resolve it using the command line.
reactions: "-1"
- name: Merge branch into current branch
env:
SLASH_COMMAND_ARG_BRANCH: ${{ github.event.client_payload.slash_command.args.unnamed.arg2 }}
if: ${{ !steps.check-conflict.outputs.merge_conflict }}
id: commit_and_push
shell: bash
run: |
set -xeuo pipefail
git merge origin/$SLASH_COMMAND_ARG_BRANCH
if [ $(git cherry -v | wc -l) -ge 1 ]; then
echo "changes=yes" >> $GITHUB_OUTPUT
echo "last_commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "last_commit_msg=$(git log -1 --pretty='%s')" >> $GITHUB_OUTPUT
else
echo "changes=no" >> $GITHUB_OUTPUT
exit 0
fi
git push origin HEAD
- name: Add reaction to command comment on nothing to do
if: ${{ !steps.check-conflict.outputs.merge_conflict && steps.commit_and_push.outputs.changes == 'no' }}
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> Already up-to-date. Nothing to commit.
reactions: "confused"
- name: Add reaction to command comment on success
if: ${{ !steps.check-conflict.outputs.merge_conflict && steps.commit_and_push.outputs.changes == 'yes' }}
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> Successfully pushed new changes:
> ${{ steps.commit_and_push.outputs.last_commit_msg }} (${{ steps.commit_and_push.outputs.last_commit_sha }})
reactions: "+1"
- name: Add reaction to command comment on failure
uses: peter-evans/create-or-update-comment@v4
if: failure()
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> **Error**: failed to execute "${{ github.event.client_payload.slash_command.args.unnamed.arg1 }}" command
reactions: "-1"
help:
if: ${{ github.event.client_payload.slash_command.args.unnamed.arg1 == 'help' || !contains(fromJson('["merge", "arg2"]'), github.event.client_payload.slash_command.args.unnamed.arg1) }}
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Update comment
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GIT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
body: |
> Command | Description
> --- | ---
> /git merge `branch` | Merge branch `branch` into current branch
reaction-type: hooray