Step 1: Create a personal access token on GitHub
Step 2: Create a GitHub repository using REST API.
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 |
## Declare some Variables GITHUB_PAT_TOKEN=' GITHUB_REPO_NAME=' GITHUB_USER_NAME=' ## Create a new GitHub repository for individual user account curl -i -H "Authorization: token $GITHUB_PAT_TOKEN" \ -d '{ "name": "$GITHUB_REPO_NAME", "description": "GitHub repo created through API", "auto_init": true, "private": true, "gitignore_template": "nanoc" }' \ https://api.github.com/user/repos ## Create a new GitHub repository for individual user account ## curl -i -H "Authorization: token $GITHUB_PAT_TOKEN" \ ## -d '{ ## "name": "$GITHUB_REPO_NAME", ## "description": "GitHub repo created through API", ## "auto_init": true, ## "private": true, ## "gitignore_template": "nanoc" ## }' \ ## https://api.github.com/orgs/ORG/repos |
Step 3: Get GitHub repository details using REST API.
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 |
## Get GitHub repository details in your account curl \ -H "Authorization: token $GITHUB_PAT_TOKEN" \ https://api.github.com/repos/$GITHUB_USER_NAME/$GITHUB_REPO_NAME ## Returns ## { ## "id": 501729121, ## "node_id": "R_kgDIKeSlxw", ## "name": "debjeet", ## "full_name": "CloudAffaire/debjeet", ## "private": true, ## "owner": { ## "login": "CloudAffaire", ## "id": 47243889, ## "node_id": "MDQ6VXNlcjZ2MjQzNzc5", ## "avatar_url": "https://avatars.githubusercontent.com/u/47243889?v=4", ## "gravatar_id": "", ## "url": "https://api.github.com/users/CloudAffaire", ## "html_url": "https://github.com/CloudAffaire", ## "followers_url": "https://api.github.com/users/CloudAffaire/followers", ## "following_url": "https://api.github.com/users/CloudAffaire/following{/other_user}", ## "gists_url": "https://api.github.com/users/CloudAffaire/gists{/gist_id}", ## "starred_url": "https://api.github.com/users/CloudAffaire/starred{/owner}{/repo}", ## "subscriptions_url": "https://api.github.com/users/CloudAffaire/subscriptions", ## "organizations_url": "https://api.github.com/users/CloudAffaire/orgs", ## "repos_url": "https://api.github.com/users/CloudAffaire/repos", ## "events_url": "https://api.github.com/users/CloudAffaire/events{/privacy}", ## "received_events_url": "https://api.github.com/users/CloudAffaire/received_events", ## "type": "User", ## "site_admin": false ## }, ## "html_url": "https://github.com/CloudAffaire/debjeet", ## "description": "mycicdpipeline", ## "fork": false, ## "url": "https://api.github.com/repos/CloudAffaire/debjeet", ## "forks_url": "https://api.github.com/repos/CloudAffaire/debjeet/forks", ## "keys_url": "https://api.github.com/repos/CloudAffaire/debjeet/keys{/key_id}", ## "collaborators_url": "https://api.github.com/repos/CloudAffaire/debjeet/collaborators{/collaborator}", ## "teams_url": "https://api.github.com/repos/CloudAffaire/debjeet/teams", ## "hooks_url": "https://api.github.com/repos/CloudAffaire/debjeet/hooks", ## "issue_events_url": "https://api.github.com/repos/CloudAffaire/debjeet/issues/events{/number}", ## "events_url": "https://api.github.com/repos/CloudAffaire/debjeet/events", ## "assignees_url": "https://api.github.com/repos/CloudAffaire/debjeet/assignees{/user}", ## "branches_url": "https://api.github.com/repos/CloudAffaire/debjeet/branches{/branch}", ## "tags_url": "https://api.github.com/repos/CloudAffaire/debjeet/tags", ## "blobs_url": "https://api.github.com/repos/CloudAffaire/debjeet/git/blobs{/sha}", ## "git_tags_url": "https://api.github.com/repos/CloudAffaire/debjeet/git/tags{/sha}", ## "git_refs_url": "https://api.github.com/repos/CloudAffaire/debjeet/git/refs{/sha}", ## "trees_url": "https://api.github.com/repos/CloudAffaire/debjeet/git/trees{/sha}", ## "statuses_url": "https://api.github.com/repos/CloudAffaire/debjeet/statuses/{sha}", ## "languages_url": "https://api.github.com/repos/CloudAffaire/debjeet/languages", ## "stargazers_url": "https://api.github.com/repos/CloudAffaire/debjeet/stargazers", ## "contributors_url": "https://api.github.com/repos/CloudAffaire/debjeet/contributors", ## "subscribers_url": "https://api.github.com/repos/CloudAffaire/debjeet/subscribers", ## "subscription_url": "https://api.github.com/repos/CloudAffaire/debjeet/subscription", ## "commits_url": "https://api.github.com/repos/CloudAffaire/debjeet/commits{/sha}", ## "git_commits_url": "https://api.github.com/repos/CloudAffaire/debjeet/git/commits{/sha}", ## "comments_url": "https://api.github.com/repos/CloudAffaire/debjeet/comments{/number}", ## "issue_comment_url": "https://api.github.com/repos/CloudAffaire/debjeet/issues/comments{/number}", ## "contents_url": "https://api.github.com/repos/CloudAffaire/debjeet/contents/{+path}", ## "compare_url": "https://api.github.com/repos/CloudAffaire/debjeet/compare/{base}...{head}", ## "merges_url": "https://api.github.com/repos/CloudAffaire/debjeet/merges", ## "archive_url": "https://api.github.com/repos/CloudAffaire/debjeet/{archive_format}{/ref}", ## "downloads_url": "https://api.github.com/repos/CloudAffaire/debjeet/downloads", ## "issues_url": "https://api.github.com/repos/CloudAffaire/debjeet/issues{/number}", ## "pulls_url": "https://api.github.com/repos/CloudAffaire/debjeet/pulls{/number}", ## "milestones_url": "https://api.github.com/repos/CloudAffaire/debjeet/milestones{/number}", ## "notifications_url": "https://api.github.com/repos/CloudAffaire/debjeet/notifications{?since,all,participating}", ## "labels_url": "https://api.github.com/repos/CloudAffaire/debjeet/labels{/name}", ## "releases_url": "https://api.github.com/repos/CloudAffaire/debjeet/releases{/id}", ## "deployments_url": "https://api.github.com/repos/CloudAffaire/debjeet/deployments", ## "created_at": "2022-06-09T06:20:55Z", ## "updated_at": "2022-06-09T06:20:55Z", ## "pushed_at": "2022-06-09T06:20:56Z", ## "git_url": "git://github.com/CloudAffaire/debjeet.git", ## "ssh_url": "git@github.com:CloudAffaire/debjeet.git", ## "clone_url": "https://github.com/CloudAffaire/debjeet.git", ## "svn_url": "https://github.com/CloudAffaire/debjeet", ## "homepage": null, ## "size": 0, ## "stargazers_count": 0, ## "watchers_count": 0, ## "language": null, ## "has_issues": true, ## "has_projects": true, ## "has_downloads": true, ## "has_wiki": true, ## "has_pages": false, ## "forks_count": 0, ## "mirror_url": null, ## "archived": false, ## "disabled": false, ## "open_issues_count": 0, ## "license": null, ## "allow_forking": true, ## "is_template": false, ## "topics": [ ## ## ], ## "visibility": "private", ## "forks": 0, ## "open_issues": 0, ## "watchers": 0, ## "default_branch": "main", ## "permissions": { ## "admin": true, ## "maintain": true, ## "push": true, ## "triage": true, ## "pull": true ## }, ## "allow_squash_merge": true, ## "allow_merge_commit": true, ## "allow_rebase_merge": true, ## "allow_auto_merge": false, ## "delete_branch_on_merge": false, ## "allow_update_branch": false, ## "network_count": 0, ## "subscribers_count": 1 ## } |
GitHub create repository REST API arguments:
- name(string)(required): The name of the repository.
- org(string)(required for organization repo): The organization name. The name is not case sensitive.
- description(string): A short description of the repository.
- homepage(string): A URL with more information about the repository.
- private(boolean): Whether the repository is private. Default: true
- visibility(string): Can be public or private for individual and public, private, and internal for organization. Default: private.
- has_issues(boolean): Either true to enable issues for this repository or false to disable them. Default: true.
- has_projects(boolean): Either true to enable projects for this repository or false to disable them. Default: true.
- has_wiki(boolean): Either true to enable the wiki for this repository or false to disable it. Default: true.
- is_template(boolean): Either true to make this repo available as a template repository or false to prevent it. Default: false.
- auto_init(boolean): Pass true to create an initial commit with empty README. Default: false.
- gitignore_template(string): Desired language or platform .gitignore template to apply.
- allow_squash_merge(boolean): Either true to allow squash-merging pull requests, or false to prevent squash-merging. Default: true.
- allow_merge_commit(boolean): Either true to allow merging pull requests with a merge commit, or false to prevent merging pull requests with merge commits. Default: true
- allow_rebase_merge(boolean): Either true to allow rebase-merging pull requests, or false to prevent rebase-merging. Default: true
- allow_auto_merge(boolean): Either true to allow auto-merge on pull requests, or false to disallow auto-merge. Default: false.
- delete_branch_on_merge(boolean): Either true to allow automatically deleting head branches when pull requests are merged, or false to prevent automatic deletion. Default: false.
To get additional details, please refer to the below documentation.
https://docs.github.com/en/rest/repos