Skip to content

Commit

Permalink
Merge pull request #137 from TWChennai/merge-in-git-cmd
Browse files Browse the repository at this point in the history
Merge git-cmd into plugin mainline, removing JGit support
  • Loading branch information
chadlwilson authored Jul 3, 2023
2 parents 814abed + 9f1991f commit 54170d9
Show file tree
Hide file tree
Showing 41 changed files with 1,794 additions and 120 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
with:
java-version: ${{ matrix.Java }}
distribution: temurin
- run: git config --global user.email "you@example.com"
- run: git config --global user.name "Your Name"
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,10 @@ GitHub.
PRERELEASE=no ./gradlew clean build githubRelease
```
* Edit the release description on `GitHub` if necessary.

## Acknowledgements

This plugin contains Git sub-process handling code originally written and released under Apache 2 licenses by
* the GoCD core team
* [Srinivas Upadhya](https://github.com/srinivasupadhya) via https://github.com/srinivasupadhya/git-cmd/
* [Ashwanth Kumar](https://github.com/ashwanthkumar) and [Chad Wilson](https://github.com/chadlwilson) via https://github.com/ashwanthkumar/git-cmd
13 changes: 5 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ java {

gocdPlugin {
id = 'git-path'
pluginVersion = '2.2.2'
pluginVersion = '2.3.0'
goCdVersion = '19.9.0'
name = 'Git Path Material Plugin'
description = 'Plugin that polls a Git repository and triggers pipelines based on sub-directory path matches'
Expand Down Expand Up @@ -49,13 +49,9 @@ ext {
dependencies {
compileOnly "cd.go.plugin:go-plugin-api:${gocdPluginVersion}"

implementation 'in.ashwanthkumar:git-cmd:2.0'
constraints {
// Control transitive dependency versions from git-cmd
implementation 'org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r'
implementation 'joda-time:joda-time:2.12.5'
implementation 'commons-io:commons-io:2.13.0'
}
implementation 'joda-time:joda-time:2.12.5'
implementation 'org.apache.commons:commons-exec:1.3'
implementation 'commons-io:commons-io:2.13.0'

implementation platform('com.fasterxml.jackson:jackson-bom:2.15.2')
implementation 'com.fasterxml.jackson.core:jackson-databind'
Expand All @@ -69,6 +65,7 @@ dependencies {
testCompileOnly "cd.go.plugin:go-plugin-api:${gocdPluginVersion}"
testImplementation 'org.mockito:mockito-junit-jupiter:5.4.0'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'uk.org.webcompere:system-stubs-jupiter:2.0.2'
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.thoughtworks.go.plugin.api.GoPlugin;
import com.thoughtworks.go.plugin.api.GoPluginIdentifier;
import com.thoughtworks.go.plugin.api.annotation.Extension;
import com.thoughtworks.go.plugin.api.annotation.Load;
import com.thoughtworks.go.plugin.api.info.PluginContext;
import com.thoughtworks.go.plugin.api.logging.Logger;
import com.thoughtworks.go.plugin.api.request.GoPluginApiRequest;
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
Expand All @@ -18,7 +16,7 @@
public class GitPathMaterialPlugin implements GoPlugin {
private static final String EXTENSION_NAME = "scm";
private static final List<String> goSupportedVersions = Arrays.asList("1.0");
private static Logger LOGGER = Logger.getLoggerFor(GitPathMaterialPlugin.class);
private static final Logger LOGGER = Logger.getLoggerFor(GitPathMaterialPlugin.class);

@Override
public void initializeGoApplicationAccessor(GoApplicationAccessor goApplicationAccessor) {
Expand All @@ -42,10 +40,4 @@ public GoPluginApiResponse handle(GoPluginApiRequest apiRequest) {
public GoPluginIdentifier pluginIdentifier() {
return new GoPluginIdentifier(EXTENSION_NAME, goSupportedVersions);
}

@Load
public void onLoad(PluginContext context) {
LOGGER.info("Loading GitPathMaterialPlugin...");
LOGGER.info("Type is {}", HelperFactory.determineType());
}
}
52 changes: 0 additions & 52 deletions src/main/java/com/thoughtworks/go/scm/plugin/HelperFactory.java

This file was deleted.

150 changes: 150 additions & 0 deletions src/main/java/com/thoughtworks/go/scm/plugin/git/GitConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package com.thoughtworks.go.scm.plugin.git;

import com.thoughtworks.go.scm.plugin.util.StringUtil;

import java.util.Objects;
import java.util.Optional;

public class GitConfig {
private String url;
private String username;
private String password;
private String branch;
private boolean subModule = false;
private boolean recursiveSubModuleUpdate = true;
private boolean noCheckout = false;
private Optional<ShallowClone> shallowClone = Optional.empty();

public GitConfig(String url) {
this.url = url;
}

public GitConfig(String url, String username, String password, String branch) {
this(url, username, password, branch, true, false);
}

public GitConfig(String url, String username, String password, String branch, boolean recursiveSubModuleUpdate, boolean shallowClone) {
this.url = url;
this.username = username;
this.password = password;
this.branch = branch;
this.recursiveSubModuleUpdate = recursiveSubModuleUpdate;
this.shallowClone = shallowClone ? Optional.of(new ShallowClone()) : Optional.empty();
}

public boolean isRemoteUrl() {
return url.startsWith("http://") || url.startsWith("https://");
}

public boolean hasCredentials() {
return !StringUtil.isBlank(url) && !StringUtil.isBlank(password);
}

public String getEffectiveUrl() {
if (isRemoteUrl() && hasCredentials()) {
return getUrlWithCredentials();
}
return getUrl();
}

public String getUrlWithCredentials() {
String[] parts = url.split("://");
return String.format("%s://%s:%s@%s", parts[0], username, password, parts[1]);
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getRemoteBranch() {
return String.format("origin/%s", getEffectiveBranch());
}

public String getEffectiveBranch() {
return StringUtil.isBlank(branch) ? "master" : branch;
}

public String getBranch() {
return branch;
}

public void setBranch(String branch) {
this.branch = branch;
}

public boolean isSubModule() {
return subModule;
}

public void setSubModule(boolean subModule) {
this.subModule = subModule;
}

public boolean isRecursiveSubModuleUpdate() {
return recursiveSubModuleUpdate;
}

public void setRecursiveSubModuleUpdate(boolean recursiveSubModuleUpdate) {
this.recursiveSubModuleUpdate = recursiveSubModuleUpdate;
}

public boolean isShallowClone() {
return shallowClone.isPresent();
}

public Optional<ShallowClone> getShallowClone() {
return shallowClone;
}

public void setShallowClone(ShallowClone shallowClone) {
this.shallowClone = Optional.of(shallowClone);
}

public boolean isNoCheckout() {
return noCheckout;
}

public void setNoCheckout(boolean noCheckout) {
this.noCheckout = noCheckout;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GitConfig gitConfig = (GitConfig) o;
return subModule == gitConfig.subModule &&
recursiveSubModuleUpdate == gitConfig.recursiveSubModuleUpdate &&
noCheckout == gitConfig.noCheckout &&
Objects.equals(url, gitConfig.url) &&
Objects.equals(username, gitConfig.username) &&
Objects.equals(password, gitConfig.password) &&
Objects.equals(branch, gitConfig.branch) &&
shallowClone.equals(gitConfig.shallowClone);
}

@Override
public int hashCode() {
return Objects.hash(url, username, password, branch, subModule, recursiveSubModuleUpdate, noCheckout, shallowClone);
}
}
Loading

0 comments on commit 54170d9

Please sign in to comment.