Skip to content

Commit 082d2b5

Browse files
authored
Merge pull request #138 from Giorgiosaud/feat/remove-environment
Feat/remove environment
2 parents 01766af + c5bf8af commit 082d2b5

File tree

35 files changed

+1184
-865
lines changed

35 files changed

+1184
-865
lines changed

npm-shrinkwrap.json

Lines changed: 247 additions & 302 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"devDependencies": {
3535
"@jest/types": "^29.5.0",
3636
"@oclif/test": "^2.3.17",
37+
"@octokit/types": "^9.2.3",
3738
"@types/chai": "^4.3.4",
3839
"@types/jest": "^29.5.1",
3940
"@types/js-nacl": "^1.3.1",

src/collaborators/add-user-permissions.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/collaborators/delete-user-permissions.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/commands/branch-protection-rules/index.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import {Command, Flags} from '@oclif/core'
2-
import getGithubToken from '../../helpers/get-github-token'
3-
import protectBranch from '../../branch-protection-rules-helpers/protect-branch'
2+
import repositoryFactory from '../../repositories/repository-factory'
3+
import {info} from '../../helpers/logger'
4+
import {validateRepoNames} from '../../helpers/validations'
45

56
export default class BranchProtectionRules extends Command {
6-
static description = 'describe the command here'
7+
static description = 'Set PRotected Branches and rules'
8+
9+
static hidden=true
710

811
static examples = [
912
`
@@ -18,6 +21,12 @@ export default class BranchProtectionRules extends Command {
1821
static strict = false
1922

2023
static flags = {
24+
likes: Flags.string({
25+
char: 'l',
26+
description: 'Likes required in pr',
27+
required: true,
28+
default: '2',
29+
}),
2130
repositories: Flags.string({
2231
char: 'r',
2332
description: 'Can be multiples repositories names',
@@ -39,22 +48,15 @@ export default class BranchProtectionRules extends Command {
3948
}
4049

4150
async run(): Promise<void> {
42-
const {flags} = await this.parse(BranchProtectionRules)
43-
const okRepoNames = flags.repositories.every((repo: string) => {
44-
return /^(([a-z]|[A-Z]|\d)+-?)*\w$/.test(repo)
45-
})
46-
if (!okRepoNames) {
47-
throw new Error('The repository string must only contain numbers leters and dash')
51+
const {flags: {repositories, branches, likes, organization}} = await this.parse(BranchProtectionRules)
52+
validateRepoNames(repositories)
53+
const octoFactory = repositoryFactory.get('octokit')
54+
for (const repo of repositories) {
55+
branches.map(async branch => {
56+
info(`Protecting branch ${branch} in ${repo}`)
57+
octoFactory.protectBranch({owner: organization, repo, branch, countReviewers: Number(likes)})
58+
info(`Branch ${branch} protected in ${repo}`)
59+
})
4860
}
49-
50-
const token = await getGithubToken(flags.organization)
51-
const branchesToProtectPromises = []
52-
for (const repo of flags.repositories) {
53-
for (const branch of flags.branches) {
54-
branchesToProtectPromises.push(protectBranch(token, flags.organization, repo, branch))
55-
}
56-
}
57-
58-
await Promise.all(branchesToProtectPromises)
5961
}
6062
}

src/commands/collaborators/index.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/commands/create-environment/index.ts

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/commands/delete-secret/index.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/commands/list-org-repositories/index.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/commands/ls/index.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {Command, Flags, ux, Args} from '@oclif/core'
2+
import repositoryFactory from '../../repositories/repository-factory'
3+
4+
export default class ListOrgRepositories extends Command {
5+
static description = 'List Org Repositories if have access'
6+
7+
static examples = [
8+
`
9+
$ github-automation ls OWNER
10+
`,
11+
]
12+
13+
static usage='list-org-repositories OWNER'
14+
15+
static strict = false
16+
17+
static flags = {
18+
page: Flags.integer({
19+
char: 'p',
20+
description: 'page number',
21+
default: 1,
22+
}),
23+
}
24+
25+
static args = {
26+
owner: Args.string({required: true}),
27+
}
28+
29+
async run(): Promise<void> {
30+
const {args: {owner}, flags: {page}} = await this.parse(ListOrgRepositories)
31+
const octoFactory = repositoryFactory.get('octokit')
32+
const repositories = await octoFactory.listRepositories({org: owner, page})
33+
ux.styledObject({
34+
repositories: repositories.data.map(repo => repo.name),
35+
page: repositories.headers.link,
36+
})
37+
}
38+
}

0 commit comments

Comments
 (0)