Skip to content

Commit

Permalink
Merge pull request #4 from riiid/enterprise
Browse files Browse the repository at this point in the history
Support Github Enterprise
  • Loading branch information
importre committed Feb 16, 2016
2 parents e186bee + 298e4a4 commit 413eef1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -26,7 +26,7 @@ buildscript {
dependencies {
...
classpath 'co.riiid:gradle-github-plugin:0.3.1'
classpath 'co.riiid:gradle-github-plugin:0.4.0'
...
}
}
Expand All @@ -43,7 +43,7 @@ apply plugin: 'co.riiid.gradle'

```groovy
plugins {
id "co.riiid.gradle" version "0.3.1"
id "co.riiid.gradle" version "0.4.0"
}
```

Expand All @@ -53,6 +53,7 @@ Add `github` configuration and set properties if you've done with 1 or 2.
### Supported Properties
Name | Type | Description
--- | --- | ---
baseUrl | String | *Optional.* The URL of Github. You can change this url as yours if you use Github Enterprise. (Default: https://api.github.com)
owner | String | *Required.* The id of your Github.
repo | String | *Required.* The name of your Github's repository.
token | String | *Required.* Github access token. Generate yours in [Settings/Tokens][settings_tokens]
Expand Down
28 changes: 27 additions & 1 deletion build.gradle
@@ -1,3 +1,14 @@
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.gradle.publish:plugin-publish-plugin:0.9.3"
}
}

plugins {
id "com.jfrog.bintray" version "1.6"
}
Expand All @@ -6,12 +17,27 @@ apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: "com.gradle.plugin-publish"

def GradleGithubPluginGroupId = 'co.riiid'
def GradleGithubPluginVersion = '0.3.2'
def GradleGithubPluginVersion = '0.4.0'
def GradleGithubPluginArtifact = 'gradle-github-plugin'
def GradleGithubPluginUrl = 'https://github.com/riiid/gradle-github-plugin'

pluginBundle {
website = GradleGithubPluginUrl
vcsUrl = GradleGithubPluginUrl
description = 'Gradle plugin for Github releases'
tags = ['github', 'gradle', 'release', 'releases']

plugins {
greetingsPlugin {
id = 'co.riiid.gradle'
displayName = 'Gradle plugin for Github releases'
}
}
}

task javadocJar(type: Jar) {
classifier = 'javadoc'
from 'build/docs/groovydoc'
Expand Down
19 changes: 19 additions & 0 deletions src/main/groovy/co/riiid/gradle/GithubExtension.groovy
Expand Up @@ -2,6 +2,9 @@ package co.riiid.gradle

class GithubExtension {

String baseUrl = "https://api.github.com"
String acceptHeader = 'application/vnd.github.v3+json'

String owner
String repo
String token
Expand All @@ -16,6 +19,14 @@ class GithubExtension {

String[] assets

String getBaseUrl() {
return baseUrl
}

String getAcceptHeader() {
return acceptHeader
}

String getOwner() {
return owner
}
Expand Down Expand Up @@ -56,6 +67,14 @@ class GithubExtension {
return assets
}

void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl
}

void setAcceptHeader(String acceptHeader) {
this.acceptHeader = acceptHeader
}

void setOwner(String owner) {
if (owner == null || owner.isEmpty()) {
throw new IllegalArgumentException("owner")
Expand Down
16 changes: 8 additions & 8 deletions src/main/groovy/co/riiid/gradle/ReleaseTask.groovy
Expand Up @@ -8,15 +8,15 @@ import org.zeroturnaround.zip.ZipUtil

class ReleaseTask extends DefaultTask {

final String BASE_URL = 'https://api.github.com'

// header
final String HEADER_ACCEPT = 'application/vnd.github.v3+json'
final String HEADER_USER_AGENT = 'gradle-github-plugin'

@TaskAction
public release() {
def http = new HttpBuilder(BASE_URL)
def baseUrl = project.github.getBaseUrl()
def accept = project.github.getAcceptHeader()

def http = new HttpBuilder(baseUrl)

def path = "/repos/" +
"${project.github.owner}/" +
Expand All @@ -38,12 +38,12 @@ class ReleaseTask extends DefaultTask {

headers.'User-Agent' = HEADER_USER_AGENT
headers.'Authorization' = "token ${project.github.token}"
headers.'Accept' = HEADER_ACCEPT
headers.'Accept' = accept

response.success = { resp, json ->
println json
if (project.github.assets != null) {
postAssets(json.upload_url, project.github.assets)
postAssets(json.upload_url, project.github.assets, accept)
}
}

Expand All @@ -53,7 +53,7 @@ class ReleaseTask extends DefaultTask {
}
}

public postAssets(uploadUrl, assets) {
public postAssets(uploadUrl, assets, accept) {
assets.each { asset ->
def file = new File(asset as String)
def name = asset.split('/')[-1]
Expand Down Expand Up @@ -91,7 +91,7 @@ class ReleaseTask extends DefaultTask {

headers.'User-Agent' = HEADER_USER_AGENT
headers.'Authorization' = "token ${project.github.token}"
headers.'Accept' = HEADER_ACCEPT
headers.'Accept' = accept
headers.'Content-Type' = contentType


Expand Down

0 comments on commit 413eef1

Please sign in to comment.