Skip to content

Commit

Permalink
Add task that will change the assignee of a github issue.
Browse files Browse the repository at this point in the history
Refs #7.
  • Loading branch information
jwir3 committed Oct 29, 2016
1 parent 7e1bbf2 commit 57d7ccc
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 29 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,43 @@ Now, to run this task, you can run:
$ gradle jiraTransition
```

## Github Integration

In order to use Github integrations, you will need to specify the following closure in your `build.gradle` file:
```
github {
repositoryName = <github project name, e.g.
username = <YOUR GITHUB USERNAME>
password = <YOUR GITHUB PASSWORD>
auth_token = <YOUR GITHUB PERSONAL OAUTH TOKEN>
}
```
You only need to provide _either_ a username/password combination, or an authentication token. A personal access token, generated from http://github.com/settings/profile is fine.

All Github tasks will be run using this configuration.

Currently, there are two tasks you can use with the Github extension (you can add more - pull requests are accepted).

### Removing Labels
You can use the `RemoveLabelsTask` to remove labels from Github upon a certain action:

```
task removeDevelopingLabel (type: com.glasstowerstudios.gruel.tasks.github.RemoveLabelsTask) {
issueNumber = 20
labels = ['developing']
}
```

### Setting Assignee
The `ChangeAssigneeTask` allows you to change the assignee of a particular Github issue:

```
task removeAssignee (type: com.glasstowerstudios.gruel.tasks.github.ChangeAssigneeTask) {
issueNumber = 20
assignee = ''
}
```

### Bumping Versions
The `bumpVersion` task is already added for you. It assumes that you have the following properties in your `gradle.properties` file:
```groovy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ public class GruelPlugin implements Plugin<Project> {
gruelExtension.adjustOutputSettings(aProject);
gruelExtension.adjustVersionNameSettings(aProject);
}

if (aProject.hasProperty('github')) {
if (!githubExtension.isValid()) {
throw new Exception("When using the github extension, you must provide a repository, along with either an authentication token, or a username/password combination");
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,67 @@ class GithubExtension {
String repositoryName;

GitHub connect() {
// We can safely assume that, by now, the github extension is valid. It's
// checked in the gruel plugin initialization code.
GitHub gh;
if (auth_token) {
gh = GitHub.connectUsingOAuth(auth_token)
} else if (username && password) {
gh = GitHub.connectUsingPassword(username, password)
if (getAuthToken()) {
gh = GitHub.connectUsingOAuth(getAuthToken())
} else if (getUsername() && getPassword()) {
gh = GitHub.connectUsingPassword(getUsername(), getPassword())
}

return gh;
}

GHRepository connectToRepository() {
GitHub gh = connect()
return gh.getRepository(repositoryName)
return gh.getRepository(getRepositoryName())
}

boolean isValid() {
return repositoryName != null && !repositoryName.isEmpty() && ((auth_token != null && !auth_token.isEmpty()) || (username != null && !username.isEmpty() && password != null && !password.isEmpty()));
}

String getUsername() {
if (!isValid()) {
throw new Exception("You must provide a repository name, and either and auth_token or username/password combination to use the github extension")
}

return username;
}

String getPassword() {
if (!isValid()) {
throw new Exception("You must provide a repository name, and either and auth_token or username/password combination to use the github extension")
}

return password;
}

String getRepositoryName() {
if (!isValid()) {
throw new Exception("You must provide a repository name, and either and auth_token or username/password combination to use the github extension")
}

return repositoryName;
}

String getAuthToken() {
if (!isValid()) {
throw new Exception("You must provide a repository name, and either and auth_token or username/password combination to use the github extension")
}

return auth_token;
}

void setAuthToken(String aToken) {
auth_token = aToken;
void setAuthToken(String auth_token) {
this.auth_token = auth_token;
}

void setUsername(String aUsername) {
username = aUsername;
void setUsername(String username) {
this.username = username;
}

void setPassword(String aPassword) {
password = aPassword;
void setPassword(String password) {
this.password = password;
}

void setRepositoryName(String repositoryName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.glasstowerstudios.gruel.tasks.github

import com.glasstowerstudios.gruel.tasks.github.GithubTask
import org.kohsuke.github.GHUser
import org.gradle.api.tasks.TaskAction

class ChangeAssigneeTask extends GithubTask {
private String assignee;
private int issueNumber;

int getIssueNumber() {
return issueNumber
}

void setIssueNumber(int issueNumber) {
this.issueNumber = issueNumber
}

String getAssignee() {
return this.assignee;
}

void setAssignee(String assignee) {
this.assignee = assignee;
}

@TaskAction
def doTask() {
def repo = project.github.connectToRepository()
def issue = repo.getIssue(this.issueNumber)
def collaborators = repo.listCollaborators()
for (GHUser nextUser : collaborators) {
if (nextUser.login == getAssignee()) {
issue.assignTo(nextUser)
return;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.kohsuke.github.GitHub
import org.kohsuke.github.GHRepository
import org.kohsuke.github.GHIssueState

class ListGithubIssuesTask extends GithubTask {
class ListIssuesTask extends GithubTask {
@TaskAction
def doTask() {
def repo = getRepository()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import org.gradle.api.tasks.TaskAction
* A type of {@link GithubTask} that will remove a set of labels from the github
* issue having a specified issue number.
*/
class RemoveLabelsFromGithubIssueTask extends GithubTask {
public static final String ALL = "all"

class RemoveLabelsTask extends GithubTask {
private int issueNumber;
private List<String> labels;

Expand Down
7 changes: 1 addition & 6 deletions test/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,14 @@ gruel {
}

github {
auth_token 'YOUR_AUTH_TOKEN_HERE'
auth_token '<YOUR AUTH TOKEN HERE>'
repositoryName 'jwir3/gruel'
}

hipchat {
auth_token = "YOUR_AUTH_TOKEN_HERE"
}

project.task('removeTaskHelpWantedLabels', type: com.glasstowerstudios.gruel.tasks.github.RemoveLabelsFromGithubIssueTask) {
labels = ['task', 'help wanted']
issueNumber = 20
}

project.task('notifyHipChat', type: com.glasstowerstudios.gruel.tasks.hipchat.HipChatNotificationTask) {
color = 'yellow'
message = 'A MESSAGE'
Expand Down

0 comments on commit 57d7ccc

Please sign in to comment.