Skip to content

Commit efcbad2

Browse files
committed
Update README.md
1 parent 7555b96 commit efcbad2

1 file changed

Lines changed: 228 additions & 5 deletions

File tree

README.md

Lines changed: 228 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,180 @@ jobs:
5656
bot:
5757
runs-on: ubuntu-latest
5858
steps:
59-
- uses: actions/checkout@v6
60-
- uses: actions/setup-python@v6
59+
- name: Checkout code
60+
uses: actions/checkout@v6
61+
62+
- name: Set up Python
63+
uses: actions/setup-python@v6
6164
with:
6265
python-version: '3.12'
63-
- run: pip install PyGithub requests
64-
- run: python demo_repos/fanex-id-bot/bot.py
66+
67+
- name: Install dependencies
68+
run: pip install PyGithub requests PyYAML PyJWT cryptography
69+
70+
# Optional: Generate GitHub App Token (if secrets are configured)
71+
# This allows the bot to post as "faneX-ID Bot" instead of "github-actions[bot]"
72+
- name: Generate GitHub App Token
73+
id: app_token
74+
if: ${{ secrets.FANEX_BOT_APP_ID != '' && secrets.FANEX_BOT_PRIVATE_KEY != '' }}
75+
run: |
76+
# Create a temporary script to generate the token
77+
cat > generate_token.py << 'EOF'
78+
import jwt
79+
import time
80+
import sys
81+
import os
82+
83+
app_id = os.environ['APP_ID']
84+
private_key = os.environ['PRIVATE_KEY']
85+
86+
# Generate JWT
87+
now = int(time.time())
88+
payload = {
89+
'iat': now - 60,
90+
'exp': now + (10 * 60),
91+
'iss': app_id
92+
}
93+
94+
token = jwt.encode(payload, private_key, algorithm='RS256')
95+
print(f"::set-output name=token::{token}")
96+
EOF
97+
98+
python generate_token.py
99+
env:
100+
APP_ID: ${{ secrets.FANEX_BOT_APP_ID }}
101+
PRIVATE_KEY: ${{ secrets.FANEX_BOT_PRIVATE_KEY }}
102+
103+
- name: Run bot
65104
env:
105+
# Use GitHub App token if available, otherwise fall back to GITHUB_TOKEN
106+
FANEX_BOT_TOKEN: ${{ steps.app_token.outputs.token }}
66107
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67108
GITHUB_REPOSITORY: ${{ github.repository }}
68109
GITHUB_EVENT_PATH: ${{ github.event_path }}
110+
run: |
111+
# Determine which token to use
112+
if [ -n "$FANEX_BOT_TOKEN" ]; then
113+
echo "✅ Using GitHub App token - comments will appear as faneX-ID Bot"
114+
export GITHUB_TOKEN="$FANEX_BOT_TOKEN"
115+
else
116+
echo "ℹ️ Using GITHUB_TOKEN - comments will appear as github-actions[bot]"
117+
echo " To use faneX-ID Bot identity, set secrets: FANEX_BOT_APP_ID and FANEX_BOT_PRIVATE_KEY"
118+
fi
119+
120+
python demo_repos/fanex-id-bot/bot.py
69121
```
70122
123+
### Token Configuration in Workflow
124+
125+
The workflow supports two authentication methods:
126+
127+
#### Method 1: GitHub App Token (Recommended)
128+
129+
**Required Secrets:**
130+
- `FANEX_BOT_APP_ID`: Your GitHub App ID
131+
- `FANEX_BOT_PRIVATE_KEY`: Your GitHub App private key (full PEM content)
132+
133+
**Benefits:**
134+
- Comments appear as "faneX-ID Bot" instead of "github-actions[bot]"
135+
- Better user experience and clearer bot identity
136+
- More professional appearance
137+
138+
**Setup:** See [Token Configuration](#token-configuration) section above.
139+
140+
#### Method 2: GitHub Actions Token (Default)
141+
142+
**No configuration needed** - uses the automatically provided `GITHUB_TOKEN`.
143+
144+
**Limitations:**
145+
- Comments appear as "github-actions[bot]"
146+
- Less personalized bot identity
147+
148+
**Token Priority:**
149+
1. If `FANEX_BOT_APP_ID` and `FANEX_BOT_PRIVATE_KEY` secrets are set, the workflow will generate a GitHub App token
150+
2. Otherwise, it falls back to the default `GITHUB_TOKEN`
151+
71152
### Installation
72153

73154
1. Copy the `fanex-id-bot` directory to your repository
74155
2. Add the workflow file to `.github/workflows/`
75156
3. The bot will automatically respond to PR comments
76157

158+
## Token Configuration
159+
160+
The bot supports two authentication methods:
161+
162+
### Option 1: GitHub App Token (Recommended)
163+
164+
Using a GitHub App token allows the bot to post comments as "faneX-ID Bot" instead of "github-actions[bot]". This provides a better user experience and clearer bot identity.
165+
166+
#### Step 1: Create a GitHub App
167+
168+
1. Go to your organization or user settings
169+
2. Navigate to **Developer settings** → **GitHub Apps**
170+
3. Click **New GitHub App**
171+
4. Configure the app:
172+
- **Name**: `faneX-ID Bot` (or your preferred name)
173+
- **Homepage URL**: Your repository URL
174+
- **Webhook**: Optional (not needed for this bot)
175+
- **Permissions**:
176+
- **Repository permissions**:
177+
- Contents: `Read`
178+
- Pull requests: `Write`
179+
- Actions: `Write`
180+
- Issues: `Write` (for comments)
181+
- **Where can this GitHub App be installed?**: Choose your organization or account
182+
5. Click **Create GitHub App**
183+
184+
#### Step 2: Generate Private Key
185+
186+
1. After creating the app, scroll down to **Private keys**
187+
2. Click **Generate a private key**
188+
3. Save the downloaded `.pem` file securely (you'll need this for the secret)
189+
190+
#### Step 3: Install the App
191+
192+
1. Click **Install App** in the app settings
193+
2. Select the organization or account where you want to install it
194+
3. Select the repositories (or all repositories)
195+
4. Click **Install**
196+
197+
#### Step 4: Get App ID
198+
199+
1. In the app settings, note the **App ID** (you'll need this for the secret)
200+
201+
#### Step 5: Configure Repository Secrets
202+
203+
Add the following secrets to your repository (Settings → Secrets and variables → Actions):
204+
205+
- **`FANEX_BOT_APP_ID`**: The App ID from step 4 (e.g., `123456`)
206+
- **`FANEX_BOT_PRIVATE_KEY`**: The entire contents of the `.pem` file from step 2
207+
208+
**Example of private key format:**
209+
```
210+
-----BEGIN RSA PRIVATE KEY-----
211+
MIIEpAIBAAKCAQEA...
212+
(multiple lines)
213+
...
214+
-----END RSA PRIVATE KEY-----
215+
```
216+
217+
#### Step 6: Update Workflow
218+
219+
The workflow will automatically detect these secrets and generate a token. No additional changes needed if using the provided workflow template.
220+
221+
### Option 2: GitHub Actions Token (Default)
222+
223+
If you don't configure a GitHub App, the bot will use the default `GITHUB_TOKEN` provided by GitHub Actions. This works out of the box but comments will appear as "github-actions[bot]".
224+
225+
**No configuration needed** - the `GITHUB_TOKEN` is automatically available in GitHub Actions workflows.
226+
227+
### Token Priority
228+
229+
The bot uses tokens in this order:
230+
1. `FANEX_BOT_TOKEN` (if GitHub App is configured)
231+
2. `GITHUB_TOKEN` (fallback, always available)
232+
77233
## Configuration
78234
79235
The bot can be configured via environment variables:
@@ -133,12 +289,79 @@ The bot consists of:
133289
- **`comment_handler.py`**: Processes PR comments and responds
134290
- **`action.yml`**: GitHub Action definition
135291
292+
## Token Setup Checklist
293+
294+
Use this checklist to set up the bot with a GitHub App token:
295+
296+
- [ ] Create GitHub App in organization/user settings
297+
- [ ] Configure app permissions (Contents: Read, Pull requests: Write, Actions: Write, Issues: Write)
298+
- [ ] Generate and download private key (.pem file)
299+
- [ ] Install the app to your organization/account
300+
- [ ] Note the App ID from app settings
301+
- [ ] Add `FANEX_BOT_APP_ID` secret to repository (Settings → Secrets → Actions)
302+
- [ ] Add `FANEX_BOT_PRIVATE_KEY` secret to repository (full PEM content, including `-----BEGIN RSA PRIVATE KEY-----` and `-----END RSA PRIVATE KEY-----`)
303+
- [ ] Test the workflow - bot comments should appear as "faneX-ID Bot"
304+
305+
## Troubleshooting
306+
307+
### Bot comments appear as "github-actions[bot]"
308+
309+
**Cause:** GitHub App token is not configured or not being generated.
310+
311+
**Solutions:**
312+
1. Verify secrets are set correctly:
313+
- Go to repository Settings → Secrets and variables → Actions
314+
- Check that `FANEX_BOT_APP_ID` and `FANEX_BOT_PRIVATE_KEY` exist
315+
2. Verify private key format:
316+
- Must include `-----BEGIN RSA PRIVATE KEY-----` at the start
317+
- Must include `-----END RSA PRIVATE KEY-----` at the end
318+
- Must include all lines in between (no truncation)
319+
3. Check workflow logs:
320+
- Look for "Generate GitHub App Token" step
321+
- Verify it runs (should show "✅ Using GitHub App token" if successful)
322+
323+
### Token generation fails
324+
325+
**Common issues:**
326+
- **Invalid App ID**: Ensure `FANEX_BOT_APP_ID` is a numeric value (e.g., `123456`)
327+
- **Invalid private key**: Ensure the entire PEM file content is copied, including headers
328+
- **App not installed**: Install the GitHub App to your organization/account
329+
- **Insufficient permissions**: Verify app has required permissions (Pull requests: Write, Actions: Write)
330+
331+
### Bot doesn't respond to commands
332+
333+
**Check:**
334+
1. Workflow is enabled and running
335+
2. Bot has write permissions to pull requests
336+
3. Commands are formatted correctly (e.g., `/retry` on its own line)
337+
4. Comment is on a PR (not an issue)
338+
136339
## Development
137340
138341
To test the bot locally:
139342
140343
```bash
141-
python bot.py --test
344+
# Set environment variables
345+
export GITHUB_TOKEN="your_token_here"
346+
export GITHUB_REPOSITORY="owner/repo"
347+
export GITHUB_EVENT_PATH="path/to/event.json"
348+
349+
# Run bot
350+
python bot.py
351+
```
352+
353+
For testing with GitHub App token:
354+
355+
```bash
356+
# Generate token first (requires APP_ID and PRIVATE_KEY)
357+
export APP_ID="your_app_id"
358+
export PRIVATE_KEY="$(cat path/to/private-key.pem)"
359+
python scripts/generate_app_token.py
360+
361+
# Then use the generated token
362+
export FANEX_BOT_TOKEN="generated_token"
363+
export GITHUB_REPOSITORY="owner/repo"
364+
python bot.py
142365
```
143366

144367
## License

0 commit comments

Comments
 (0)