This repository has been archived by the owner on Nov 26, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 298
JGithub Improvements. Labels management #1124
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0662bc1
Created two methods to get labels ina repo
177c761
Fixed a typo error
a2af3f2
Fixed typo errors
104ec76
Create Label method
b93f3f8
Override Http
a218fc6
Added editLabel method
f521e8f
Fixed response code validation error
da45452
Delete label method
8da1f00
get a list of labels by issue
9fbee34
Removed getLabels by issue
c68f1d0
Fixed tab space error :(
58da69e
Fixed tab space error :(
a28434d
Fixed tab space error :(
581d422
Fixed tab space error :(
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,45 @@ public function createComment($user, $repo, $issueId, $body) | |
return json_decode($response->body); | ||
} | ||
|
||
/** | ||
* Method to create a label on a repo. | ||
* | ||
* @param string $user The name of the owner of the GitHub repository. | ||
* @param string $repo The name of the GitHub repository. | ||
* @param string $name The label name. | ||
* @param string $color The label color. | ||
* | ||
* @return object | ||
* | ||
* @since 12.1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change these to 12.2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And by that he means 12.3 ;-) |
||
*/ | ||
public function createLabel($user, $repo, $name, $color) | ||
{ | ||
// Build the request path. | ||
$path = '/repos/' . $user . '/' . $repo . '/labels'; | ||
|
||
// Build the request data. | ||
$data = json_encode( | ||
array( | ||
'name' => $name, | ||
'color' => $color | ||
) | ||
); | ||
|
||
// Send the request. | ||
$response = $this->client->post($this->fetchUrl($path), $data); | ||
|
||
// Validate the response code. | ||
if ($response->code != 201) | ||
{ | ||
// Decode the error response and throw an exception. | ||
$error = json_decode($response->body); | ||
throw new DomainException($error->message, $response->code); | ||
} | ||
|
||
return json_decode($response->body); | ||
} | ||
|
||
/** | ||
* Method to delete a comment on an issue. | ||
* | ||
|
@@ -135,6 +174,36 @@ public function deleteComment($user, $repo, $commentId) | |
} | ||
} | ||
|
||
/** | ||
* Method to delete a label on a repo. | ||
* | ||
* @param string $user The name of the owner of the GitHub repository. | ||
* @param string $repo The name of the GitHub repository. | ||
* @param string $label The label name. | ||
* | ||
* @return object | ||
* | ||
* @since 12.1 | ||
*/ | ||
public function deleteLabel($user, $repo, $label) | ||
{ | ||
// Build the request path. | ||
$path = '/repos/' . $user . '/' . $repo . '/labels/' . $label; | ||
|
||
// Send the request. | ||
$response = $this->client->delete($this->fetchUrl($path)); | ||
|
||
// Validate the response code. | ||
if ($response->code != 204) | ||
{ | ||
// Decode the error response and throw an exception. | ||
$error = json_decode($response->body); | ||
throw new DomainException($error->message, $response->code); | ||
} | ||
|
||
return json_decode($response->body); | ||
} | ||
|
||
/** | ||
* Method to update an issue. | ||
* | ||
|
@@ -257,6 +326,46 @@ public function editComment($user, $repo, $commentId, $body) | |
return json_decode($response->body); | ||
} | ||
|
||
/** | ||
* Method to update a label on a repo. | ||
* | ||
* @param string $user The name of the owner of the GitHub repository. | ||
* @param string $repo The name of the GitHub repository. | ||
* @param string $label The label name. | ||
* @param string $name The label name. | ||
* @param string $color The label color. | ||
* | ||
* @return object | ||
* | ||
* @since 12.1 | ||
*/ | ||
public function editLabel($user, $repo, $label, $name, $color) | ||
{ | ||
// Build the request path. | ||
$path = '/repos/' . $user . '/' . $repo . '/labels/' . $label; | ||
|
||
// Build the request data. | ||
$data = json_encode( | ||
array( | ||
'name' => $name, | ||
'color' => $color | ||
) | ||
); | ||
|
||
// Send the request. | ||
$response = $this->client->patch($this->fetchUrl($path), $data); | ||
|
||
// Validate the response code. | ||
if ($response->code != 200) | ||
{ | ||
// Decode the error response and throw an exception. | ||
$error = json_decode($response->body); | ||
throw new DomainException($error->message, $response->code); | ||
} | ||
|
||
return json_decode($response->body); | ||
} | ||
|
||
/** | ||
* Method to get a single issue. | ||
* | ||
|
@@ -349,6 +458,65 @@ public function getComments($user, $repo, $issueId, $page = 0, $limit = 0) | |
return json_decode($response->body); | ||
} | ||
|
||
/** | ||
* Method to get a specific label on a repo. | ||
* | ||
* @param string $user The name of the owner of the GitHub repository. | ||
* @param string $repo The name of the GitHub repository. | ||
* @param string $name The label name to get. | ||
* | ||
* @return object | ||
* | ||
* @since 12.1 | ||
*/ | ||
public function getLabel($user, $repo, $name) | ||
{ | ||
// Build the request path. | ||
$path = '/repos/' . $user . '/' . $repo . '/labels/' . $name; | ||
|
||
// Send the request. | ||
$response = $this->client->get($this->fetchUrl($path)); | ||
|
||
// Validate the response code. | ||
if ($response->code != 200) | ||
{ | ||
// Decode the error response and throw an exception. | ||
$error = json_decode($response->body); | ||
throw new DomainException($error->message, $response->code); | ||
} | ||
|
||
return json_decode($response->body); | ||
} | ||
|
||
/** | ||
* Method to get the list of labels on a repo. | ||
* | ||
* @param string $user The name of the owner of the GitHub repository. | ||
* @param string $repo The name of the GitHub repository. | ||
* | ||
* @return array | ||
* | ||
* @since 12.1 | ||
*/ | ||
public function getLabels($user, $repo) | ||
{ | ||
// Build the request path. | ||
$path = '/repos/' . $user . '/' . $repo . '/labels'; | ||
|
||
// Send the request. | ||
$response = $this->client->get($this->fetchUrl($path)); | ||
|
||
// Validate the response code. | ||
if ($response->code != 200) | ||
{ | ||
// Decode the error response and throw an exception. | ||
$error = json_decode($response->body); | ||
throw new DomainException($error->message, $response->code); | ||
} | ||
|
||
return json_decode($response->body); | ||
} | ||
|
||
/** | ||
* Method to list an authenticated user's issues. | ||
* | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you removing this? This increases the chance of breaking things when something is added to the JHttp constructor that is required.