-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow specifying name, label and contentType of releaseAssets
refactor on the way. Add new repo closure to semanticRelease extension. Here both ghToken and all releaseAssets must be given. Mark old changeLog.ghToken as deprecated Add new UpdateGithubRelease task. The release is now updated using this task instead of release.doLast
- Loading branch information
Showing
14 changed files
with
469 additions
and
159 deletions.
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
77 changes: 77 additions & 0 deletions
77
src/main/groovy/de/gliderpilot/gradle/semanticrelease/GitRepo.groovy
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.gliderpilot.gradle.semanticrelease | ||
|
||
import groovy.transform.PackageScope | ||
import org.gradle.api.Task | ||
import org.gradle.api.tasks.bundling.AbstractArchiveTask | ||
|
||
abstract class GitRepo { | ||
|
||
private Map<File, Asset> releaseAssets = [:].withDefault { file -> new Asset(file) } | ||
|
||
@PackageScope | ||
Collection<Asset> getReleaseAssets() { | ||
return releaseAssets.values() | ||
} | ||
|
||
|
||
Asset releaseAsset(Map<String, String> params = [:], AbstractArchiveTask task) { | ||
params.builtBy = task | ||
releaseAsset(params, task.outputs.files.singleFile) | ||
} | ||
|
||
Asset releaseAsset(Map<String, String> params = [:], File file) { | ||
Asset asset = releaseAssets[file] | ||
params.each { key, value -> | ||
asset."$key" = value | ||
} | ||
asset | ||
} | ||
|
||
abstract String diffUrl(String previousTag, String currentTag) | ||
|
||
abstract String commitUrl(String abbreviatedId) | ||
} | ||
|
||
class Asset { | ||
final File file | ||
Task builtBy | ||
String name | ||
String label | ||
String contentType | ||
|
||
Asset(File file) { | ||
this.file = file | ||
name = file.name | ||
contentType = URLConnection.guessContentTypeFromName(name) ?: "application/octet-stream" | ||
} | ||
|
||
Asset name(String name) { | ||
this.name = name | ||
this | ||
} | ||
|
||
Asset label(String label) { | ||
this.label = label | ||
this | ||
} | ||
|
||
Asset contentType(String contentType) { | ||
this.contentType = contentType | ||
this | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/groovy/de/gliderpilot/gradle/semanticrelease/GithubRepo.groovy
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package de.gliderpilot.gradle.semanticrelease | ||
|
||
import com.jcabi.github.Github | ||
import com.jcabi.github.RtGithub | ||
import groovy.transform.Memoized | ||
import groovy.transform.PackageScope | ||
import org.ajoberstar.grgit.Grgit | ||
|
||
import java.util.regex.Matcher | ||
|
||
class GithubRepo extends GitRepo { | ||
|
||
private final Grgit grgit | ||
|
||
private Github github | ||
|
||
@PackageScope | ||
Github getGithub() { | ||
github | ||
} | ||
|
||
GithubRepo(Grgit grgit) { | ||
this.grgit = grgit | ||
} | ||
|
||
void setGhToken(String token) { | ||
if (token) | ||
github = new RtGithub(token) | ||
} | ||
|
||
@PackageScope | ||
@Memoized | ||
String getMnemo() { | ||
String repositoryUrl = grgit.remote.list().find { it.name == 'origin' }.url | ||
Matcher matcher = repositoryUrl =~ /.*github.com[\/:]((?:.+?)\/(?:.+?))(?:\.git)/ | ||
if (!matcher) | ||
return null | ||
return matcher.group(1) | ||
} | ||
|
||
private String repositoryUrl(String suffix) { | ||
if (!mnemo) | ||
return null | ||
return "https://github.com/${mnemo}/$suffix" | ||
} | ||
|
||
String diffUrl(String previousTag, String currentTag) { | ||
if (!(previousTag && currentTag)) | ||
return null | ||
repositoryUrl("compare/${previousTag}...${currentTag}") | ||
} | ||
|
||
String commitUrl(String abbreviatedId) { | ||
if (!abbreviatedId) | ||
return null | ||
repositoryUrl("commit/${abbreviatedId}") | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.