Skip to content

Commit 9ff1d4d

Browse files
committed
fix: add mk repo
1 parent 5902f69 commit 9ff1d4d

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/commands/mk-repo/index.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {Command, Flags} from '@oclif/core'
2+
import {validateRepoNames} from '../../helpers/validations'
3+
import repositoryFactory from '../../repositories/repository-factory'
4+
export default class MkRepo extends Command {
5+
static description = 'Create repos'
6+
7+
static examples = [
8+
`
9+
you must have a personal github token to set the first time that uses this tool
10+
$ github-automation mk-repo --organization OWNER --repositories NAME1 NAME2 ... NAMEn
11+
$ github-automation mk-repo -o Owner -r NAME1 NAME2 ... NAMEn
12+
`,
13+
]
14+
15+
static usage='mk-repo -o ORG -r REPOS'
16+
17+
static strict = false
18+
19+
static flags = {
20+
organization: Flags.string({
21+
char: 'o',
22+
description: 'A single string containing the organization name',
23+
required: true,
24+
}),
25+
repositories: Flags.string({
26+
char: 'r',
27+
description: 'Can be multiples repositories names',
28+
required: true,
29+
multiple: true,
30+
}),
31+
32+
help: Flags.help({char: 'h'}),
33+
}
34+
35+
async run(): Promise<void> {
36+
const {flags: {organization, repositories}} = await this.parse(MkRepo)
37+
validateRepoNames(repositories)
38+
const octoFactory = repositoryFactory.get('octokit')
39+
for (const repo of repositories) {
40+
console.log('Creating repo', repo)
41+
await octoFactory.createRepo({organization, repo})
42+
console.log('Repo created', repo)
43+
}
44+
}
45+
}

src/repositories/octokit-repository.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,20 @@ export type renameBranchResponse=Endpoints['POST /repos/{owner}/{repo}/branches/
3030
export type getBranchResponse=Endpoints['GET /repos/{owner}/{repo}/branches/{branch}']['response'];
3131
export type readFile=Endpoints['GET /repos/{owner}/{repo}/contents/{path}']['response'];
3232
export type writeFile=Endpoints['PUT /repos/{owner}/{repo}/contents/{path}']['response'];
33+
export type createRepoResponse=Endpoints['POST /orgs/{org}/repos']['response'];
34+
3335
export default {
36+
async createRepo({organization, repo}:{organization: string, repo: string}):Promise<createRepoResponse> {
37+
const octokit = await octokitClient({org: organization})
38+
return octokit.request('POST /orgs/{org}/repos', {
39+
org: organization,
40+
name: repo,
41+
private: true,
42+
headers: {
43+
'X-GitHub-Api-Version': '2022-11-28',
44+
},
45+
})
46+
},
3447
async setEnvironmentVariable({owner, repo, name, environment_name, value}:{owner:string, repo:string, name:string, environment_name:string, value: string}):Promise<postVariableResponse> {
3548
const octokit = await octokitClient({org: owner})
3649
const repository_id = await this.getRepositoryId({owner, repo})

0 commit comments

Comments
 (0)