GitHub Action to manage repository operations (create, delete, archive) via the GitHub API
- Create new repositories with comprehensive settings
- Delete repositories safely
- Archive repositories while maintaining data
- Configurable repository settings including:
- Basic settings (description, visibility, initialization)
- Features (issues, projects, wiki, discussions)
- Merge settings (squash, merge, rebase)
- Branch protection rules
- Team access control
The GitHub token used (GH_REPO_TOKEN) requires the following permissions:
repo- Required for all private repository operationspublic_repo- Required for public repository operations (can be used instead ofrepofor public repos)delete_repo- Required for repository deletionwrite:org- Required for managing team access to repositoriesread:org- Required for reading team information
Note: The following permissions are not required but may be included in your token:
repo:status- For commit status accessrepo_deployment- For deployment status accessrepo:invite- For repository invitationssecurity_events- For security events access
- "Administration" repository permissions (write) - Required for repository management
- "Organization" permissions (read and write) - Required for team access management
- Go to your GitHub organization settings
- Navigate to "Developer settings" > "Personal access tokens" > "Tokens (classic)"
- Generate a new token with the required scopes
- Store the token securely in your repository secrets as
GH_REPO_TOKEN
Note: For security best practices:
- Use the minimum required permissions
- Regularly rotate your tokens
- Never commit tokens to your repository
- Use repository secrets for token storage
name: Create Repository
on:
workflow_dispatch:
inputs:
repository_name:
description: 'Name of the repository to create'
required: true
default: 'sample-repo'
jobs:
create-repo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Create Repository
uses: actionsforge/actions-repo-ops@v1
env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
GH_ORG_NAME: ${{ secrets.GH_ORG_NAME }}
with:
operation: create
repository_name: ${{ inputs.repository_name }}
description: "Created via GitHub Actions"
private: true
auto_init: true
gitignore_template: Node
license_template: mit
homepage: "https://example.com"
has_issues: true
has_projects: true
has_wiki: true
has_discussions: true
team_id: 123456
allow_squash_merge: true
allow_merge_commit: true
allow_rebase_merge: true
allow_auto_merge: true
delete_branch_on_merge: true
allow_update_branch: true
default_branch: main
use_squash_pr_title_as_default: true
squash_merge_commit_title: PR_TITLE
squash_merge_commit_message: PR_BODY
merge_commit_title: PR_TITLE
merge_commit_message: PR_BODYname: Delete Repository
on:
workflow_dispatch:
inputs:
repository_name:
description: "Name of the repository to delete"
required: true
default: sample-repo
jobs:
delete-repo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Delete Repository
uses: actionsforge/actions-repo-ops@v1
env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
GH_ORG_NAME: ${{ secrets.GH_ORG_NAME }}
with:
operation: delete
repository_name: ${{ inputs.repository_name }}name: Archive Repository
on:
workflow_dispatch:
inputs:
repository_name:
description: "Name of the repository to archive"
required: true
default: sample-repo
jobs:
archive-repo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Archive Repository
uses: actionsforge/actions-repo-ops@v1
env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
GH_ORG_NAME: ${{ secrets.GH_ORG_NAME }}
with:
operation: archive
repository_name: ${{ inputs.repository_name }}| Input | Description | Default |
|---|---|---|
operation |
Operation to perform (create/delete/archive) | - |
repository_name |
Name of the repository | - |
github_token |
GitHub token with repo scope | - |
| Input | Description | Default |
|---|---|---|
description |
Repository description | - |
private |
Make repository private | false |
auto_init |
Initialize with README | false |
gitignore_template |
Add .gitignore template | - |
license_template |
Add license template | - |
homepage |
Repository homepage URL | - |
| Input | Description | Default |
|---|---|---|
has_issues |
Enable issues | true |
has_projects |
Enable projects | true |
has_wiki |
Enable wiki | true |
has_discussions |
Enable discussions | false |
team_id |
Team ID to grant access | - |
| Input | Description | Default |
|---|---|---|
allow_squash_merge |
Allow squash merging | true |
allow_merge_commit |
Allow merge commits | true |
allow_rebase_merge |
Allow rebase merging | true |
allow_auto_merge |
Allow auto-merge | false |
delete_branch_on_merge |
Delete branch after merge | false |
allow_update_branch |
Allow branch updates | false |
default_branch |
Default branch name | main |
use_squash_pr_title_as_default |
Use PR title for squash merge | false |
| Input | Description | Options | Default |
|---|---|---|---|
squash_merge_commit_title |
Squash merge commit title | PR_TITLE, COMMIT_OR_PR_TITLE |
- |
squash_merge_commit_message |
Squash merge commit message | PR_BODY, COMMIT_MESSAGES, BLANK |
- |
merge_commit_title |
Merge commit title | PR_TITLE, MERGE_MESSAGE |
- |
merge_commit_message |
Merge commit message | PR_BODY, PR_TITLE, BLANK |
- |
You can run repository operations directly via the command line by setting the required environment variables:
# Required environment variables
export GH_REPO_TOKEN="your-github-token" # GitHub token with repo scope
export GH_ORG_NAME="your-org-name" # Target organization name
# Run the action with required inputs
INPUT_OPERATION=create \
INPUT_REPOSITORY_NAME=test-repo \
INPUT_DESCRIPTION="Test repository" \
INPUT_PRIVATE=true \
INPUT_AUTO_INIT=true \
INPUT_GITIGNORE_TEMPLATE=Node \
INPUT_LICENSE_TEMPLATE=mit \
INPUT_HOMEPAGE="https://example.com" \
INPUT_HAS_ISSUES=true \
INPUT_HAS_PROJECTS=true \
INPUT_HAS_WIKI=true \
INPUT_HAS_DISCUSSIONS=true \
INPUT_TEAM_ID=123456 \
INPUT_ALLOW_SQUASH_MERGE=true \
INPUT_ALLOW_MERGE_COMMIT=true \
INPUT_ALLOW_REBASE_MERGE=true \
INPUT_ALLOW_AUTO_MERGE=true \
INPUT_DELETE_BRANCH_ON_MERGE=true \
INPUT_ALLOW_UPDATE_BRANCH=true \
INPUT_DEFAULT_BRANCH=main \
INPUT_USE_SQUASH_PR_TITLE_AS_DEFAULT=true \
INPUT_SQUASH_MERGE_COMMIT_TITLE=PR_TITLE \
INPUT_SQUASH_MERGE_COMMIT_MESSAGE=PR_BODY \
INPUT_MERGE_COMMIT_TITLE=PR_TITLE \
INPUT_MERGE_COMMIT_MESSAGE=PR_BODY \
node dist/index.jsAll inputs can be set as environment variables with the INPUT_ prefix. See the Inputs section above for all available options.
| Output | Description |
|---|---|
status |
Operation status (success/failure) |
message |
Operation result message |
repository_url |
URL of the created repository (create operation only) |
The action handles various error cases gracefully:
- Repository already exists (treated as success)
- Repository not found (treated as success for delete/archive)
- Permission errors
- Invalid input parameters
- API rate limits
- Network errors
This project is licensed under the MIT License - see the LICENSE file for details.