GitHub Repo Configurator - A Tool for Modifiying a Large Number of Repositorys

Tool for making changes to x amount of repos.

Code

Its written in Python and only requires the requests library to be installed.

GitHub Repo - c-jaenicke/repo_configurator

Features

Changing Repos

GitHub Documentation

NameTypeDescription
namestringThe name of the repository.
descriptionstringA short description of the repository.
homepagestringA URL with more information about the repository.
privatebooleanEither true to make the repository private or false to make it public. Default: false.
visibilitystringCan be public or private
security_and_analysisobject or nullableSpecify which security and analysis features to enable or disable. For example, to enable GitHub Advanced Security, use this data in the body of the PATCH request: {“security_and_analysis”: {“advanced_security”: {“status”: “enabled”}}}. If you have admin permissions for a private repository covered by an Advanced Security license, you can check which security and analysis features are currently enabled by using a GET /repos/{owner}/{repo} request.
has_issuesbooleanEither true to enable issues for this repository or false to disable them.
has_projectsbooleanEither true to enable projects for this repository or false to disable them. Note: If you’re creating a repository in an organization that has disabled repository projects, the default is false, and if you pass true, the API returns an error.
has_wikibooleanEither true to enable the wiki for this repository or false to disable it.
is_templatebooleanEither true to make this repo available as a template repository or false to prevent it.
default_branchstringUpdates the default branch for this repository.
allow_squash_mergebooleanEither true to allow squash-merging pull requests, or false to prevent squash-merging.
allow_merge_commitbooleanEither true to allow merging pull requests with a merge commit, or false to prevent merging pull requests with merge commits.
allow_rebase_mergebooleanEither true to allow rebase-merging pull requests, or false to prevent rebase-merging.
allow_auto_mergebooleanEither true to allow auto-merge on pull requests, or false to disallow auto-merge.
delete_branch_on_mergebooleanEither true to allow automatically deleting head branches when pull requests are merged, or false to prevent automatic deletion.
archivedbooleantrue to archive this repository. Note: You cannot unarchive repositories through the API.
allow_forkingbooleanEither true to allow private forks, or false to prevent private forks.

Example changes.json for making changes

{
    "name": "a cool repo",
    "description": "some text",
    "homepage": null,
    "private": true,
    "visibility": "private",
    "has_issues": true,
    "has_projects": true,
    "has_wiki": true,
    "is_template": false,
    "default_branch": "main",
    "allow_squash_merge": true,
    "allow_merge_commit": true,
    "allow_rebase_merge": true,
    "allow_auto_merge": false,
    "delete_branch_on_merge": false,
    "archived": false,
    "allow_forking": true
}

Creating Repos

GitHub Documentation

NameTypeDescription
namestringRequired. The name of the repository.
descriptionstringA short description of the repository.
homepagestringA URL with more information about the repository.
privatebooleanWhether the repository is private. Default: false
has_issuesbooleanWhether issues are enabled. Default: true
has_projectsbooleanWhether projects are enabled. Default: true
has_wikibooleanWhether the wiki is enabled. Default: true
team_idintegerThe id of the team that will be granted access to this repository. This is only valid when creating a repository in an organization.
auto_initbooleanWhether the repository is initialized with a minimal README. Default: false
gitignore_templatestringThe desired language or platform to apply to the .gitignore.
license_templatestringThe license keyword of the open source license for this repository.
allow_squash_mergebooleanWhether to allow squash merges for pull requests. Default: true
allow_merge_commitbooleanWhether to allow merge commits for pull requests. Default: true
allow_rebase_mergebooleanWhether to allow rebase merges for pull requests. Default: true
allow_auto_mergebooleanWhether to allow Auto-merge to be used on pull requests. Default: false
delete_branch_on_mergebooleanWhether to delete head branches when pull requests are merged. Default: false
has_downloadsbooleanWhether downloads are enabled. Default: true
is_templatebooleanWhether this repository acts as a template that can be used to generate new repositories. Default: false

Example changes.json for creating a repo

{
    "name": "a new repo i created",
    "description": "this repo does a thing",
    "homepage": null,
    "private": false,
    "has_issues": true,
    "has_projects": true,
    "has_wiki": true,
    "team_id": null,
    "auto_init": false,
    "gitignore_template": null,
    "license_template": null,
    "allow_squash_merge": true,
    "allow_merge_commit": true,
    "allow_rebase_merge": true,
    "allow_auto_merge": false,
    "delete_branch_on_merge": false,
    "has_downloads": true,
    "is_template": false
}

Requirements

To work this requires a GitHub personal access token, check here (GitHub Documentation) on how to create one.

This needs to be inserted in the main.py in line 6: PAT_token = "TOKEN HERE"

How to Use

usage: GitHub Repo Normalizer [-h] [-repo REPO] [-json] [-view]
                              [-changes CHANGES]
                              {getinfo,changerepo,createrepo}

Normalize GitHub repo settings

positional arguments:
  {getinfo,changerepo,createrepo}
                        Sets operation to be performed:
                            getinfo: returns info on the given repo, e.g. if its private and number of issues
                                Args:
                                    -repo <value> ; default = repos.txt ; takes a file to be iterated through or a single repo
                                        repo needs to be formatted as "owner/repo_name", e.g. "c-jaenicke/repo_configurator"
                                    -view ; default = false ; displays info about the repo in the terminal
                                    -json ; default = false ; prints the info about the repo in a json file

                            changerepo: changes the settings of a repo
                                Args:
                                    -repo <value> ; default = repos.txt ; takes a file to be iterated through or a single repo
                                        repo needs to be formatted as "owner/repo_name", e.g. "c-jaenicke/repo_configurator"
                                    -changes <value> ; default = changes.json ; specifies the file that will be read, which contains the changes to be made, see README.md for possible values

                            createrepo: creates a repo with the specified settings
                                Args:
                                    -changes <value> ; default = changes.json ; specifies which settings the new repo will have, see README.md for possible values


optional arguments:
  -h, --help            show this help message and exit
  -repo REPO            Default = repos.txt ; Reads a specified file for a list of repos, or takes a single repo, the names need to be formatted as "owner/repo_name" e.g. c-jaenicke/repo_configurator .
  -json                 Default = False ;  When used the info about a repo will be stored in a .json file.
  -view                 Default = False ;  When used the info about a repo will be displayed in the terminal.
  -changes CHANGES      Default = changes.json ; Reads a specified file for changes to be made in a json format. Please use https://jsonformatter.curiousconcept.com/ for testing your JSON. Possible values are in the README.md.
Last modified 2022.02.18