-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
156 lines (140 loc) · 5.66 KB
/
action.yml
File metadata and controls
156 lines (140 loc) · 5.66 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: "GitHub Bot Auto-Answer"
description: "Auto answer to issues and PRs"
inputs:
token:
description: "GitHub token for authentication"
required: true
issue_comment:
description: "Custom message to respond to issues"
required: false
default: "Thank you for creating this issue! Our team will review it soon."
pr_comment:
description: "Custom message to respond to PRs"
required: false
default: "Thank you for your PR! We will review it shortly."
issue_label:
description: "Label to add to issues"
required: false
default: "triage"
pr_label:
description: "Label to add to PRs"
required: false
default: "review-needed"
add_labels:
description: "Add labels automatically (true/false)"
required: false
type: boolean
default: false
use_personal_token:
description: "Enable personal token for respond"
required: false
type: boolean
default: false
personal_token:
description: "GitHub personal token"
required: false
type: string
default: ""
runs:
using: "composite"
steps:
- name: Respond to Issues (Personal Token)
if: github.event_name == 'issues' && github.event.action == 'opened' && inputs.use_personal_token == true
shell: bash
env:
AUTHOR_TOKEN: ${{ inputs.personal_token }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_COMMENT: ${{ inputs.issue_comment }}
ISSUE_LABEL: ${{ inputs.issue_label }}
ADD_LABELS: ${{ inputs.add_labels }}
run: |
echo "👤 Responding as a user with personal token in issue #$ISSUE_NUMBER"
if [[ -z "$AUTHOR_TOKEN" ]]; then
echo "::warning::No PERSONAL_ACCESS_TOKEN configured. Omitting personal comment."
exit 0
fi
# Comment with personal token
GH_TOKEN="$AUTHOR_TOKEN" gh issue comment "$ISSUE_NUMBER" \
--repo "$GITHUB_REPOSITORY" \
--body "$ISSUE_COMMENT"
echo "✅ Comment personal added to issue #$ISSUE_NUMBER"
# Add label if enabled
if [[ "$ADD_LABELS" == "true" && -n "$ISSUE_LABEL" ]]; then
GH_TOKEN="$AUTHOR_TOKEN" gh issue edit "$ISSUE_NUMBER" \
--repo "$GITHUB_REPOSITORY" \
--add-label "$ISSUE_LABEL" || echo "⚠️ Label '$ISSUE_LABEL' podría no existir"
echo "✅ Label '$ISSUE_LABEL' agregado"
fi
- name: Respond to Issues (Bot Token)
if: github.event_name == 'issues' && github.event.action == 'opened' && inputs.use_personal_token != true
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_COMMENT: ${{ inputs.issue_comment }}
ISSUE_LABEL: ${{ inputs.issue_label }}
ADD_LABELS: ${{ inputs.add_labels }}
run: |
echo "🤖 Bot processing issue #$ISSUE_NUMBER"
# Comment in the issue
gh issue comment "$ISSUE_NUMBER" \
--repo "$GITHUB_REPOSITORY" \
--body "$ISSUE_COMMENT"
echo "✅ Comment bot added to issue #$ISSUE_NUMBER"
# Add label if enabled
if [[ "$ADD_LABELS" == "true" && -n "$ISSUE_LABEL" ]]; then
gh issue edit "$ISSUE_NUMBER" \
--repo "$GITHUB_REPOSITORY" \
--add-label "$ISSUE_LABEL" || echo "⚠️ Label '$ISSUE_LABEL' podría no existir"
echo "✅ Label '$ISSUE_LABEL' added"
fi
- name: Respond to Pull Requests (Personal Token)
if: github.event_name == 'pull_request' && github.event.action == 'opened' && inputs.use_personal_token == true
shell: bash
env:
AUTHOR_TOKEN: ${{ inputs.personal_token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_COMMENT: ${{ inputs.pr_comment }}
PR_LABEL: ${{ inputs.pr_label }}
ADD_LABELS: ${{ inputs.add_labels }}
run: |
echo "👤 Responding as a user with personal token in PR #$PR_NUMBER"
if [[ -z "$AUTHOR_TOKEN" ]]; then
echo "::warning::No PERSONAL_ACCESS_TOKEN configured. Omitting personal comment."
exit 0
fi
# Comment with personal token
GH_TOKEN="$AUTHOR_TOKEN" gh pr comment "$PR_NUMBER" \
--repo "$GITHUB_REPOSITORY" \
--body "$PR_COMMENT"
echo "✅ Comment personal added to PR #$PR_NUMBER"
# Agregar label si está habilitado
if [[ "$ADD_LABELS" == "true" && -n "$PR_LABEL" ]]; then
GH_TOKEN="$AUTHOR_TOKEN" gh pr edit "$PR_NUMBER" \
--repo "$GITHUB_REPOSITORY" \
--add-label "$PR_LABEL" || echo "⚠️ Label '$PR_LABEL' podría no existir"
echo "✅ Label '$PR_LABEL' agregado"
fi
- name: Respond to Pull Requests (Bot Token)
if: github.event_name == 'pull_request' && github.event.action == 'opened' && inputs.use_personal_token != true
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_COMMENT: ${{ inputs.pr_comment }}
PR_LABEL: ${{ inputs.pr_label }}
ADD_LABELS: ${{ inputs.add_labels }}
run: |
echo "🤖 Bot processing PR #$PR_NUMBER"
# Comment in the PR
gh pr comment "$PR_NUMBER" \
--repo "$GITHUB_REPOSITORY" \
--body "$PR_COMMENT"
echo "✅ Comment bot added to PR #$PR_NUMBER"
# Add label if enabled
if [[ "$ADD_LABELS" == "true" && -n "$PR_LABEL" ]]; then
gh pr edit "$PR_NUMBER" \
--repo "$GITHUB_REPOSITORY" \
--add-label "$PR_LABEL" || echo "⚠️ Label '$PR_LABEL' podría no existir"
echo "✅ Label '$PR_LABEL' added"
fi