-
Notifications
You must be signed in to change notification settings - Fork 384
151 lines (137 loc) · 5.77 KB
/
help-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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: Help Command
on:
issue_comment:
types: [created]
workflow_dispatch:
inputs:
pr_number:
description: 'Pull Request number to post help comment on'
required: true
type: string
permissions:
issues: write
pull-requests: write
jobs:
help:
if: ${{ (github.event.issue.pull_request && github.event.comment.body == '/help') || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
steps:
- name: Show Available Commands
uses: actions/github-script@v7
with:
script: |
const sections = {
commands: {
deploy: {
title: '## `/deploy`',
purpose: '**Purpose:** Deploy a review app for your pull request',
details: [
'**What it does:**',
'- Creates a new review app in Control Plane',
'- Deploys your changes to the review environment',
'- Provides a unique URL to preview your changes',
'- Shows build and deployment progress in real-time',
'',
'**Optional Configuration:**',
'- `WAIT_TIMEOUT`: Deployment timeout in seconds (default: 900)',
' - Must be a positive integer',
' - Example: `/deploy timeout=1800`'
]
},
destroy: {
title: '## `/destroy`',
purpose: '**Purpose:** Remove the review app for your pull request',
details: [
'**What it does:**',
'- Deletes the review app from Control Plane',
'- Cleans up associated resources',
'- Updates PR with deletion status'
]
}
},
setup: {
title: '## Environment Setup',
sections: [
{
title: '**Required Environment Secrets:**',
items: [
'- `CPLN_TOKEN_STAGING`: Control Plane authentication token',
'- `CPLN_TOKEN_PRODUCTION`: Control Plane authentication token'
]
},
{
title: '**Required GitHub Actions Variables:**',
items: [
'- `CPLN_ORG_STAGING`: Control Plane authentication token',
'- `CPLN_ORG_PRODUCTION`: Control Plane authentication token'
]
},
{
title: '**Required GitHub Actions Variables (these need to match your control_plane.yml file:**',
items: [
'- `PRODUCTION_APP_NAME`: Control Plane production app name',
'- `STAGING_APP_NAME`: Control Plane staging app name',
'- `REVIEW_APP_PREFIX`: Control Plane review app prefix'
]
}
],
note: 'Optional: Configure `WAIT_TIMEOUT` in GitHub Actions variables to customize deployment timeout'
},
integration: {
title: '## Control Plane Integration',
details: [
'1. Review app naming convention:',
' ```',
' ${{ vars.REVIEW_APP_PREFIX }}-<pr-number>',
' ```',
'2. Console URL: `https://console.cpln.io/console/org/{CPLN_ORG}/gvc/{APP_NAME}/-info`'
]
},
cleanup: {
title: '## Automatic Cleanup',
details: [
'Review apps are automatically destroyed when:',
'1. The pull request is closed',
'2. The `/destroy` command is used',
'3. A new deployment is requested (old one is cleaned up first)'
]
},
help: {
title: '## Need Help?',
details: [
'For additional assistance:',
'1. Check the [Control Plane documentation](https://docs.controlplane.com/)',
'2. Contact the infrastructure team',
'3. Open an issue in this repository'
]
}
};
const generateHelpText = () => {
const parts = ['# Available Commands', ''];
// Add commands
Object.values(sections.commands).forEach(cmd => {
parts.push(cmd.title, cmd.purpose, '', ...cmd.details, '');
});
parts.push('---');
// Add setup section
parts.push(sections.setup.title, '');
sections.setup.sections.forEach(section => {
parts.push(section.title, ...section.items, '');
});
parts.push(sections.setup.note, '');
// Add remaining sections
['integration', 'cleanup', 'help'].forEach(section => {
parts.push(sections[section].title, '', ...sections[section].details, '');
});
return parts.join('\n');
};
const helpText = generateHelpText();
const prNumber = context.eventName === 'workflow_dispatch'
? parseInt(context.payload.inputs.pr_number)
: context.issue.number;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: helpText
});