Skip to content

Commit 55675c4

Browse files
authored
Merge pull request #121 from scm-manager/develop
[pull] develop from scm-manager:develop
2 parents 46d2654 + cb42d08 commit 55675c4

File tree

4 files changed

+92
-9
lines changed

4 files changed

+92
-9
lines changed

Jenkinsfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pipeline {
116116
expression { return isBuildSuccess() }
117117
}
118118
steps {
119-
withPublishEnivronment {
119+
withPublishEnvironment {
120120
gradle "-PenablePackaging publish"
121121
}
122122
}
@@ -286,7 +286,7 @@ void withCheckEnvironment(Closure<Void> closure) {
286286
closure.call()
287287
}
288288

289-
void withPublishEnivronment(Closure<Void> closure) {
289+
void withPublishEnvironment(Closure<Void> closure) {
290290
withCredentials([
291291
usernamePassword(credentialsId: 'packages-scm-manager-org', usernameVariable: 'ORG_GRADLE_PROJECT_packagesScmManagerUsername', passwordVariable: 'ORG_GRADLE_PROJECT_packagesScmManagerPassword'),
292292
usernamePassword(credentialsId: 'cesmarvin', usernameVariable: 'ORG_GRADLE_PROJECT_gitHubUsername', passwordVariable: 'ORG_GRADLE_PROJECT_gitHubApiToken'),

build-plugins/src/main/groovy/com/cloudogu/scm/PackagingPlugin.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class PackagingPlugin implements Plugin<Project> {
3535
project.ext.ReleaseYaml = ReleaseYamlTask
3636
project.ext.HttpUploadTask = HttpUploadTask
3737
project.ext.GitHubUploadTask = GitHubUploadTask
38+
project.ext.ScmManagerUploadTask = ScmManagerUploadTask
3839
}
3940

4041
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package com.cloudogu.scm
26+
27+
import com.google.common.base.Strings
28+
import groovy.json.JsonOutput
29+
import org.eclipse.jetty.client.HttpClient
30+
import org.eclipse.jetty.client.api.Request
31+
import org.eclipse.jetty.client.util.StringContentProvider
32+
import org.eclipse.jetty.http.HttpMethod
33+
import org.gradle.api.tasks.Input
34+
import org.gradle.api.tasks.Internal
35+
import org.gradle.api.tasks.Optional
36+
37+
import java.nio.charset.StandardCharsets
38+
39+
class ScmManagerUploadTask extends UploadTask {
40+
41+
@Input
42+
@Optional
43+
String apiToken
44+
45+
@Input
46+
String server
47+
48+
@Input
49+
String namespace
50+
51+
@Input
52+
String repo
53+
54+
@Input
55+
String path
56+
57+
@Input
58+
String branch = "master"
59+
60+
@Input
61+
String message
62+
63+
@Override
64+
Request createRequest(HttpClient client) {
65+
String[] pathComponents = path.split("/")
66+
String filename = pathComponents[pathComponents.length - 1]
67+
String directory = path.substring(0, path.length() - filename.length() - 1)
68+
Request request = client.newRequest("${server}/api/v2/edit/${namespace}/${repo}/create/${directory}")
69+
request.method(HttpMethod.POST)
70+
request.header("Accept", "application/json")
71+
request.header("Content-Type", "application/json")
72+
if (!Strings.isNullOrEmpty(apiToken)) {
73+
request.header("Authorization","Bearer ${apiToken}")
74+
}
75+
76+
def body = [
77+
commitMessage: message,
78+
branch: branch,
79+
fileName: filename,
80+
fileContent: artifact.text
81+
]
82+
request.content(new StringContentProvider(JsonOutput.toJson(body), StandardCharsets.UTF_8))
83+
return request
84+
}
85+
}

scm-packaging/release-yaml/build.gradle

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import com.cloudogu.scm.GitHubUploadTask
25+
import com.cloudogu.scm.ScmManagerUploadTask
2626

2727
plugins {
2828
id 'org.scm-manager.packaging'
@@ -48,16 +48,13 @@ task distribution(type: ReleaseYaml) {
4848
configuration = configurations.packageYaml
4949
}
5050

51-
task publish(type: GitHubUploadTask) {
52-
owner = "scm-manager"
51+
task publish(type: ScmManagerUploadTask) {
52+
server = "https://ecosystem.cloudogu.com/scm"
53+
namespace = "scm-manager"
5354
repo = "website"
5455
path = "content/releases/${project.version.replace('.', '-')}.yml"
5556
branch = "master"
5657
message = "Add release descriptor for ${project.version}"
57-
author {
58-
name = "CES Marvin"
59-
email = "cesmarvin@cloudogu.com"
60-
}
6158
artifact = file('build/libs/release.yml')
6259
if (project.hasProperty("gitHubApiToken")) {
6360
apiToken = project.property("gitHubApiToken")

0 commit comments

Comments
 (0)