diff --git a/README.md b/README.md index b6b88c1..f96fd52 100644 --- a/README.md +++ b/README.md @@ -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 = + password = + auth_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 diff --git a/gruel/src/main/groovy/com/glasstowerstudios/gruel/GruelPlugin.groovy b/gruel/src/main/groovy/com/glasstowerstudios/gruel/GruelPlugin.groovy index 4fc9b8b..416bc38 100644 --- a/gruel/src/main/groovy/com/glasstowerstudios/gruel/GruelPlugin.groovy +++ b/gruel/src/main/groovy/com/glasstowerstudios/gruel/GruelPlugin.groovy @@ -42,12 +42,6 @@ public class GruelPlugin implements Plugin { 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"); - } - } } } } diff --git a/gruel/src/main/groovy/com/glasstowerstudios/gruel/extensions/GithubExtension.groovy b/gruel/src/main/groovy/com/glasstowerstudios/gruel/extensions/GithubExtension.groovy index 1032d45..2fe6bbe 100644 --- a/gruel/src/main/groovy/com/glasstowerstudios/gruel/extensions/GithubExtension.groovy +++ b/gruel/src/main/groovy/com/glasstowerstudios/gruel/extensions/GithubExtension.groovy @@ -17,13 +17,11 @@ 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; @@ -31,7 +29,7 @@ class GithubExtension { GHRepository connectToRepository() { GitHub gh = connect() - return gh.getRepository(repositoryName) + return gh.getRepository(getRepositoryName()) } boolean isValid() { @@ -39,31 +37,47 @@ class GithubExtension { } 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) { diff --git a/gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/ChangeAssigneeTask.groovy b/gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/ChangeAssigneeTask.groovy new file mode 100644 index 0000000..b40a2c6 --- /dev/null +++ b/gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/ChangeAssigneeTask.groovy @@ -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; + } + } + } +} diff --git a/gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/ListGithubIssuesTask.groovy b/gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/ListIssuesTask.groovy similarity index 91% rename from gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/ListGithubIssuesTask.groovy rename to gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/ListIssuesTask.groovy index f4817a7..6bf0b4b 100644 --- a/gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/ListGithubIssuesTask.groovy +++ b/gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/ListIssuesTask.groovy @@ -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() diff --git a/gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/RemoveLabelsFromGithubIssueTask.groovy b/gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/RemoveLabelsTask.groovy similarity index 90% rename from gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/RemoveLabelsFromGithubIssueTask.groovy rename to gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/RemoveLabelsTask.groovy index 3c4af28..da141cc 100644 --- a/gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/RemoveLabelsFromGithubIssueTask.groovy +++ b/gruel/src/main/groovy/com/glasstowerstudios/gruel/tasks/github/RemoveLabelsTask.groovy @@ -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 labels; diff --git a/test/java/build.gradle b/test/java/build.gradle index 3a866b0..ca659df 100644 --- a/test/java/build.gradle +++ b/test/java/build.gradle @@ -44,7 +44,7 @@ gruel { } github { - auth_token 'YOUR_AUTH_TOKEN_HERE' + auth_token '' repositoryName 'jwir3/gruel' } @@ -52,11 +52,6 @@ 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'