Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ github-pr-status/build
gitlab-mr-status/build
gerrit-cs-status/build
stash-pr-status/build
gitea-pr-status/build
common/out
github-pr-status/out
gitlab-mr-status/out
gerrit-cs-status/out
stash-pr-status/out
gitea-pr-status/out


# App #
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Supported:
* GitHub Pull Request status
* Stash Pull Request status
* Gerrit Change Set status
* Gitea Pull Request status

## Requirements
These plugins require GoCD version >= v15.x or above
Expand All @@ -20,7 +21,7 @@ These plugins require GoCD version >= v15.x or above

## Configuration

- You will see `Github Pull Requests status notifier` / `Stash Pull Requests status notifier` / `Gerrit Change Set status notifier` / `GitLab Feature Branch status notifier` on plugin listing page
- You will see `Github Pull Requests status notifier` / `Stash Pull Requests status notifier` / `Gerrit Change Set status notifier` / `GitLab Feature Branch status notifier` / `Gitea Pull Requests status notifier` on plugin listing page
![Plugins listing page][1]

- You can configure the plugin (this feature requires GoCD version >= v15.2, use system properties to configure the plugin). The details should be as follows:
Expand Down Expand Up @@ -115,6 +116,18 @@ Eg:
-Dgo.plugin.build.status.gitlab.oauth=XXXX
```

#### Gitea
**Setup:**
- You need to provide `GoCD Base URL`, `Gitea Base URL`, `Username`, `Password` using the plugin configuration view.
- (or) through system property `go.plugin.build.status.go-server`, `go.plugin.build.status.gitea.endpoint`, `go.plugin.build.status.gitea.username`, `go.plugin.build.status.gitea.password`.
Eg:
```
-Dgo.plugin.build.status.go-server=https://gitea.com
-Dgo.plugin.build.status.gitea.endpoint=https://gitea.com
-Dgo.plugin.build.status.gitea.username=johndoe
-Dgo.plugin.build.status.gitea.password=thisaintapassword
```

## FAQs

[1]: images/list-plugin.png "List Plugin"
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ gocdPlugin {
project(':gerrit-cs-status').tasks.jar,
project(':github-pr-status').tasks.jar,
project(':gitlab-mr-status').tasks.jar,
project(':stash-pr-status').tasks.jar
project(':stash-pr-status').tasks.jar,
project(':gitea-pr-status').tasks.jar,
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void shouldDelegateUpdateStatusToProviderWithCorrectParameters() throws E
String expectedPipelineInstance = String.format("%s/%s/%s/%s", pipelineName, pipelineCounter, stageName, stageCounter);
String expectedStageResult = "Passed";

Map requestBody = createRequestBodyMap(expectedURL, expectedUsername, expectedRevision, expectedPRId, pipelineName, pipelineCounter, stageName, stageCounter, expectedStageResult);
Map<String, Object> requestBody = createRequestBodyMap(expectedURL, expectedUsername, expectedRevision, expectedPRId, pipelineName, pipelineCounter, stageName, stageCounter, expectedStageResult);
plugin.handleStageNotification(createGoPluginAPIRequest(requestBody));

verify(provider).updateStatus(eq(expectedURL), any(PluginSettings.class), eq("1"), eq(expectedRevision), eq(expectedPipelineStage), eq(expectedStageResult), eq("http://localhost:8153/go/pipelines/" + expectedPipelineInstance));
Expand Down Expand Up @@ -145,32 +145,32 @@ public String requestBody() {
};
}

private Map createRequestBodyMap(String url, String username, String revision, String prId, String pipelineName, String pipelineCounter, String stageName, String stageCounter, String stageResult) {
Map materialRevisionMap = new HashMap();
Map materialMap = new HashMap();
private Map<String, Object> createRequestBodyMap(String url, String username, String revision, String prId, String pipelineName, String pipelineCounter, String stageName, String stageCounter, String stageResult) {
Map<String, Object> materialRevisionMap = new HashMap<>();
Map<String, Object> materialMap = new HashMap<>();
materialMap.put("type", "scm");
materialMap.put("plugin-id", POLLER_PLUGIN_ID);
Map configurationMap = new HashMap();
Map<String, Object> configurationMap = new HashMap<>();
configurationMap.put("url", url);
configurationMap.put("username", username);
materialMap.put("scm-configuration", configurationMap);
materialRevisionMap.put("material", materialMap);

List modifications = new ArrayList();
Map modificationMap = new HashMap();
List<Map<String, Object>> modifications = new ArrayList<>();
Map<String, Object> modificationMap = new HashMap<>();
modificationMap.put("revision", revision);
Map modificationDataMap = new HashMap();
Map<String, Object> modificationDataMap = new HashMap<>();
modificationDataMap.put("PR_ID", prId);
modificationMap.put("data", modificationDataMap);
modifications.add(modificationMap);
materialRevisionMap.put("modifications", modifications);

Map pipelineMap = new HashMap();
List buildCause = new ArrayList();
Map<String, Object> pipelineMap = new HashMap<>();
List<Map<String, Object>> buildCause = new ArrayList<>();
buildCause.add(materialRevisionMap);
pipelineMap.put("build-cause", buildCause);

Map stageMap = new HashMap();
Map<String, Object> stageMap = new HashMap<>();
stageMap.put("name", stageName);
stageMap.put("counter", stageCounter);
stageMap.put("result", stageResult);
Expand All @@ -179,12 +179,12 @@ private Map createRequestBodyMap(String url, String username, String revision, S
pipelineMap.put("name", pipelineName);
pipelineMap.put("counter", pipelineCounter);

Map requestBody = new HashMap();
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("pipeline", pipelineMap);
return requestBody;
}

private DefaultGoPluginApiRequest createGoPluginAPIRequest(Map requestBody) {
private DefaultGoPluginApiRequest createGoPluginAPIRequest(Map<String, Object> requestBody) {
DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest(BuildStatusNotifierPlugin.EXTENSION_NAME, "1.0", BuildStatusNotifierPlugin.REQUEST_STAGE_STATUS);
request.setRequestBody(JSONUtils.toJSON(requestBody));
return request;
Expand Down
51 changes: 51 additions & 0 deletions gitea-pr-status/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2022 Thoughtworks, Inc.
*
* 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.
*/

plugins {
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
implementation project(":common")
}

gocdPlugin {
id = 'gitea.pr.status'
pluginVersion = rootProject.gocdPlugin.pluginVersion
goCdVersion = rootProject.gocdPlugin.goCdVersion
name = 'Gitea Pull Requests status notifier'
description = 'Updates build status for Gitea pull request'
vendorName = rootProject.gocdPlugin.vendorName
vendorUrl = rootProject.gocdPlugin.vendorUrl

githubRepo {
owner = rootProject.gocdPlugin.githubRepo.owner
repo = rootProject.gocdPlugin.githubRepo.repo
token = rootProject.gocdPlugin.githubRepo.token
}

pluginProject = project

prerelease = rootProject.gocdPlugin.prerelease
prereleaseDryrun = rootProject.gocdPlugin.prereleaseDryrun
assetsToRelease = [] // Released by root project
}

version = gocdPlugin.fullVersion(project)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2022 Thoughtworks, Inc.
*
* 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 com.tw.go.plugin;

import com.thoughtworks.go.plugin.api.annotation.Extension;
import com.tw.go.plugin.provider.GiteaProvider;
import com.tw.go.plugin.provider.Provider;

@Extension
public class GiteaBuildStatusNotifierPlugin extends BuildStatusNotifierPlugin {
@Override
protected Provider loadProvider() {
try {
return new GiteaProvider();
} catch (Exception e) {
throw new RuntimeException("could not create provider", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2022 Thoughtworks, Inc.
*
* 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 com.tw.go.plugin.provider;

import com.tw.go.plugin.setting.PluginConfigurationView;

import java.util.HashMap;
import java.util.Map;

import static com.tw.go.plugin.setting.DefaultPluginConfigurationView.*;
import static com.tw.go.plugin.util.ConfigurationUtils.createField;

public class GiteaConfigurationView implements PluginConfigurationView {

@Override
public String templateName() {
return "plugin-settings-gitea.template.html";
}

@Override
public Map<String, Object> fields() {
Map<String, Object> response = new HashMap<>();
response.put(PLUGIN_SETTINGS_SERVER_BASE_URL, createField("GoCD Base URL", null, true, false, "0"));
response.put(PLUGIN_SETTINGS_END_POINT, createField("Gitea Base URL", null, true, false, "1"));
response.put(PLUGIN_SETTINGS_USERNAME, createField("Username", null, true, false, "2"));
response.put(PLUGIN_SETTINGS_PASSWORD, createField("Password", null, true, true, "3"));
return response;
}
}
Loading