Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
fix(repo): update label & create label
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Garant committed Sep 14, 2019
1 parent 8fc3240 commit d0d5faa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -917,16 +917,16 @@ gh re --clone --user eduardolundgren --repo gh --protocol https

#### Examples

- Create a label for a repository.
- Create a label for a repository (_color is a hex code with or without literal hex symbol_).

```
gh re --label --new bug --color color --repo gh
gh re --label --new bug --color '#7057ff' --repo gh
```

- Create a label for a user's repository.

```
gh re --label --new bug --color color --user eduardolundgren --repo gh
gh re --label --new bug --color '#7057ff' --user eduardolundgren --repo gh
```

### 8. Delete Label
Expand Down Expand Up @@ -990,7 +990,7 @@ gh re --label --list --user eduardolundgren --repo gh

#### Examples

- Update a label for a repository.
- Update a label for a repository (_color is a hex code with or without literal hex symbol_).

```
gh re --label --update bug --color color --repo gh
Expand Down
2 changes: 0 additions & 2 deletions src/cmds/gists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ Gists.prototype.run = async function(done) {
if (options.new) {
const privacy = options.private ? 'private' : 'public'

options.new = options.new

beforeHooks('gists.new', instance)

logger.log(
Expand Down
47 changes: 25 additions & 22 deletions src/cmds/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,12 @@ Repo.prototype.run = async function(done) {
)

try {
const { data } = await instance.createLabel(user)
console.log('data', data)
await instance.createLabel(user)
} catch (err) {
throw new Error(`Can't create label.\n${err}`)
}

beforeHooks('repo.createLabel', instance)
afterHooks('repo.createLabel', instance)
} else if (options.update) {
beforeHooks('repo.updateLabel', instance)

Expand All @@ -292,7 +291,7 @@ Repo.prototype.run = async function(done) {

status === 200 && logger.log('Success')

beforeHooks('repo.updateLabel', instance)
afterHooks('repo.updateLabel', instance)
}
} else if (options.list && !options.label) {
if (options.organization) {
Expand Down Expand Up @@ -363,13 +362,13 @@ Repo.prototype.clone_ = function(user, repo, repo_url) {
git.clone(url.parse(repo_url).href, repo)
}

Repo.prototype.createLabel = async function(user): Promise<Octokit.IssuesCreateLabelResponse> {
Repo.prototype.createLabel = function(user): Promise<Octokit.IssuesCreateLabelResponse> {
const instance = this
const options = instance.options

const payload: Octokit.IssuesCreateLabelParams = {
owner: user,
color: options.color,
color: normalizeColor(options.color),
name: options.new,
repo: options.repo,
}
Expand All @@ -378,20 +377,20 @@ Repo.prototype.createLabel = async function(user): Promise<Octokit.IssuesCreateL
payload.description = options.description
}

return await instance.GitHub.issues.createLabel(payload)
return instance.GitHub.issues.createLabel(payload)
}

Repo.prototype.delete = async function(user, repo): Promise<Octokit.ReposDeleteResponse> {
Repo.prototype.delete = function(user, repo): Promise<Octokit.ReposDeleteResponse> {
const instance = this
const payload = {
repo,
owner: user,
}

return await instance.GitHub.repos.delete(payload)
return instance.GitHub.repos.delete(payload)
}

Repo.prototype.deleteLabel = async function(user): Promise<Octokit.IssuesDeleteLabelResponse> {
Repo.prototype.deleteLabel = function(user): Promise<Octokit.IssuesDeleteLabelResponse> {
const instance = this
const options = instance.options

Expand All @@ -401,21 +400,21 @@ Repo.prototype.deleteLabel = async function(user): Promise<Octokit.IssuesDeleteL
repo: options.repo,
}

return await instance.GitHub.issues.deleteLabel(payload)
return instance.GitHub.issues.deleteLabel(payload)
}

Repo.prototype.get = async function(user, repo): Promise<Octokit.IssuesGetResponse> {
Repo.prototype.get = function(user, repo): Promise<Octokit.IssuesGetResponse> {
const instance = this

const payload = {
repo,
owner: user,
}

return await instance.GitHub.repos.get(payload)
return instance.GitHub.repos.get(payload)
}

Repo.prototype.list = async function(
Repo.prototype.list = function(
user
): Promise<Octokit.AnyResponse | Octokit.ReposListForOrgResponse> {
const instance = this
Expand Down Expand Up @@ -444,7 +443,7 @@ Repo.prototype.list = async function(
}
}

return await instance.GitHub.paginate(instance.GitHub.repos[method].endpoint(payload))
return instance.GitHub.paginate(instance.GitHub.repos[method].endpoint(payload))
}

Repo.prototype.listCallback_ = function(repos): void {
Expand Down Expand Up @@ -487,7 +486,7 @@ Repo.prototype.listCallback_ = function(repos): void {
}
}

Repo.prototype.listLabels = async function(user): Promise<Octokit.IssuesListLabelsForRepoResponse> {
Repo.prototype.listLabels = function(user): Promise<Octokit.IssuesListLabelsForRepoResponse> {
const instance = this
const options = instance.options

Expand All @@ -498,7 +497,7 @@ Repo.prototype.listLabels = async function(user): Promise<Octokit.IssuesListLabe
...(options.per_page && { per_page: options.per_page }),
}

return await instance.GitHub.issues.listLabelsForRepo(payload)
return instance.GitHub.issues.listLabelsForRepo(payload)
}

Repo.prototype.listLabelsCallback_ = function(err, labels): void {
Expand Down Expand Up @@ -532,7 +531,7 @@ Repo.prototype.fork = async function(): Promise<Octokit.ReposCreateForkResponse>
return await instance.GitHub.repos.createFork(payload)
}

Repo.prototype.new = async function(): Promise<
Repo.prototype.new = function(): Promise<
Octokit.ReposCreateInOrgResponse | Octokit.ReposCreateForAuthenticatedUserResponse
> {
const instance = this
Expand Down Expand Up @@ -568,19 +567,23 @@ Repo.prototype.new = async function(): Promise<
payload.org = options.organization
}

return await instance.GitHub.repos[method](payload)
return instance.GitHub.repos[method](payload)
}

Repo.prototype.updateLabel = async function(user): Promise<Octokit.IssuesUpdateLabelResponse> {
Repo.prototype.updateLabel = function(user): Promise<Octokit.IssuesUpdateLabelResponse> {
const instance = this
const options = instance.options

const payload: Octokit.IssuesUpdateLabelParams = {
owner: user,
color: options.color,
color: normalizeColor(options.color),
current_name: options.update,
repo: options.repo,
}

return await instance.GitHub.issues.updateLabel(payload)
return instance.GitHub.issues.updateLabel(payload)
}

function normalizeColor(color) {
return color.includes('#') ? color.replace('#', '') : color
}

0 comments on commit d0d5faa

Please sign in to comment.