Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ Now your PRs get friendly names automatically. Your teammates will thank you (pr

### Inputs

| Input | Description | Required | Default |
| ---------- | ------------------------------------------------------------- | -------- | ------------- |
| `number` | Number to convert (auto-detects PR number) | No | Auto-detected |
| `theme` | Word theme to use (see available themes below) | No | `cities-20` |
| `template` | Output template with `{codename}` and `{number}` placeholders | No | - |
| Input | Description | Required | Default |
| ---------- | ------------------------------------------------------------- | -------- | ---------------------- |
| `number` | Number to convert (auto-detects PR number) | No | Auto-detected |
| `theme` | Word theme to use (see available themes below) | No | `cities-20` |
| `template` | Output template with `{codename}` and `{number}` placeholders | No | - |
| `token` | GitHub token for API access (for push events) | No | `GITHUB_TOKEN` env var |

### Outputs

Expand Down Expand Up @@ -188,10 +189,37 @@ The magic happens in the [codenames library](https://github.com/kriasoft/codenam

No randomness, no database, no external calls. Just pure, predictable naming.

## GitHub Token Setup

For push events and other non-PR contexts, the action needs GitHub API access to find the associated PR. Add these permissions to your workflow:

```yaml
jobs:
codename:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read # Required for API fallback
steps:
- uses: kriasoft/pr-codename@v1
with:
token: ${{ secrets.GITHUB_TOKEN }} # Explicit token
```

Or use the environment variable approach:

```yaml
- uses: kriasoft/pr-codename@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Environment variable
```

The action will gracefully handle missing tokens by falling back to manual number input.

## Common Issues

**Q: Why am I getting "Could not determine number"?**
A: The action tries to auto-detect PR numbers, but if you're not in a PR context, pass the `number` input manually.
A: The action tries to auto-detect PR numbers, but if you're not in a PR context, pass the `number` input manually or ensure proper GitHub token permissions.

**Q: Can I use custom word lists?**
A: Not directly in this action, but you can fork the [codenames library](https://github.com/kriasoft/codenames) and add your own themes.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ inputs:
template:
description: "Output template with placeholders. Supports: {codename}, {number}"
required: false
token:
description: "GitHub token for API access (defaults to GITHUB_TOKEN environment variable)"
required: false

outputs:
codename:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29899,7 +29899,7 @@ async function getNumber() {
return _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.issue.number;
}
// Method 4: API fallback using commit SHA
const token = process.env.GITHUB_TOKEN;
const token = (0,_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)("token") || process.env.GITHUB_TOKEN;
if (!token) {
console.log("No GITHUB_TOKEN provided for API fallback");
return null;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async function getNumber(): Promise<number | null> {
}

// Method 4: API fallback using commit SHA
const token = process.env.GITHUB_TOKEN;
const token = getInput("token") || process.env.GITHUB_TOKEN;
if (!token) {
console.log("No GITHUB_TOKEN provided for API fallback");
return null;
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pr-codename",
"version": "0.0.0",
"version": "1.0.0",
"private": true,
"type": "module",
"dependencies": {
Expand All @@ -9,10 +9,10 @@
"codenames": "^1.1.0"
},
"devDependencies": {
"@eslint/js": "^9.31.0",
"@eslint/js": "^9.32.0",
"@types/node": "^24.1.0",
"@vercel/ncc": "^0.38.3",
"eslint": "^9.31.0",
"eslint": "^9.32.0",
"jiti": "^2.5.1",
"prettier": "^3.6.2",
"typescript": "^5.8.3",
Expand Down