This repository has been archived by the owner on Jul 29, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit - first working version, needs clean-up
- Loading branch information
Petr Siroky
committed
Oct 19, 2015
0 parents
commit 7a477a0
Showing
14 changed files
with
758 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
target/ | ||
local/ | ||
work/ | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
.idea/ | ||
*.iml |
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,54 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>plugin</artifactId> | ||
<version>1.609.3</version><!-- which version of Jenkins is this plugin built against? --> | ||
</parent> | ||
|
||
<groupId>org.kie.jenkins-ci.plugins</groupId> | ||
<artifactId>kie-pr-builds-helper</artifactId> | ||
<version>0.1-SNAPSHOT</version> | ||
<packaging>hpi</packaging> | ||
|
||
<!-- get every artifact through repo.jenkins-ci.org, which proxies all the artifacts that we need --> | ||
<repositories> | ||
<repository> | ||
<id>repo.jenkins-ci.org</id> | ||
<url>http://repo.jenkins-ci.org/public/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<pluginRepositories> | ||
<pluginRepository> | ||
<id>repo.jenkins-ci.org</id> | ||
<url>http://repo.jenkins-ci.org/public/</url> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>git-client</artifactId> | ||
<version>1.19.0</version> | ||
</dependency> | ||
<!--<dependency>--> | ||
<!--<groupId>org.jenkins-ci.main</groupId>--> | ||
<!--<artifactId>maven-plugin</artifactId>--> | ||
<!--<version>2.12.1</version>--> | ||
<!--</dependency>--> | ||
<dependency> | ||
<groupId>org.kohsuke</groupId> | ||
<artifactId>github-api</artifactId> | ||
<version>1.69</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
111 changes: 111 additions & 0 deletions
111
src/main/java/org/kie/jenkinsci/plugins/kieprbuildshelper/GitHubPRSummary.java
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,111 @@ | ||
/* | ||
* Copyright 2015 JBoss by Red Hat | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* 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 org.kie.jenkinsci.plugins.kieprbuildshelper; | ||
|
||
import org.kohsuke.github.GHPullRequest; | ||
import org.kohsuke.github.GitHub; | ||
|
||
import java.io.IOException; | ||
|
||
public class GitHubPRSummary { | ||
|
||
private final String targetRepo; | ||
private final String targetRepoOwner; | ||
private final int id; | ||
private final String sourceBranch; | ||
private final String sourceRepoOwner; | ||
|
||
public GitHubPRSummary(String targetRepo, String targetRepoOwner, int id, String sourceBranch, String sourceRepoOwner) { | ||
this.targetRepo = targetRepo; | ||
this.targetRepoOwner = targetRepoOwner; | ||
this.id = id; | ||
this.sourceBranch = sourceBranch; | ||
this.sourceRepoOwner = sourceRepoOwner; | ||
} | ||
|
||
public String getTargetRepo() { | ||
return targetRepo; | ||
} | ||
|
||
public String getTargetRepoOwner() { | ||
return targetRepoOwner; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public String getSourceBranch() { | ||
return sourceBranch; | ||
} | ||
|
||
public String getSourceRepoOwner() { | ||
return sourceRepoOwner; | ||
} | ||
|
||
/** | ||
* Creates a PR summary from provided link, getting some of the info directly from Github. | ||
* | ||
* @param prLink pull request link, e.g. https://github.com/droolsjbpm/drools-wb/pull/77 | ||
* @param github configured Github instance used to talk to Github REST API | ||
* | ||
* @return summary info about GitHub PR as needed by {@link UpstreamReposBuilder} | ||
*/ | ||
public static GitHubPRSummary fromPRLink(String prLink, String sourceBranch, GitHub github) { | ||
String str = preProcessPRLink(prLink); | ||
String[] parts = str.split("/"); | ||
String targetRepoOwner = parts[0]; | ||
String targetRepo = parts[1]; | ||
// parts[2] == "pull", not needed | ||
int id = Integer.parseInt(parts[3]); | ||
GHPullRequest pr = null; | ||
try { | ||
pr = github.getRepository(targetRepoOwner + "/" + targetRepo).getPullRequest(id); | ||
String sourceRepoOwner = pr.getHead().getRepository().getOwner().getLogin(); | ||
return new GitHubPRSummary( | ||
targetRepo, | ||
targetRepoOwner, | ||
id, | ||
sourceBranch, | ||
sourceRepoOwner | ||
); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Error when getting info about PR " + prLink, e); | ||
} | ||
} | ||
|
||
/** | ||
* Pre-processes the PR link, removing the unnecessary parts like "github.com" and trailing slash. | ||
* | ||
* @param prLink the full PR link | ||
* | ||
* @return part of the PR link that contains the important info (repo owner, repo name and PR ID) | ||
*/ | ||
private static String preProcessPRLink(String prLink) { | ||
int ghComIdx = prLink.indexOf("github.com"); | ||
if (ghComIdx < 0) { | ||
throw new IllegalArgumentException("Provided Github PR link '" + prLink + "' is not valid, as it does not contain the string github.com!"); | ||
} | ||
String noGhComPrInfo = prLink.substring(ghComIdx + "github.com/".length()); | ||
// now the string contains "<repoOwner>/<repoName>/pull/<pullId>" | ||
if (noGhComPrInfo.endsWith("/")) { | ||
return noGhComPrInfo.substring(0, noGhComPrInfo.length() - 1); | ||
} else { | ||
return noGhComPrInfo; | ||
} | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/org/kie/jenkinsci/plugins/kieprbuildshelper/GitHubRepository.java
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,66 @@ | ||
/* | ||
* Copyright 2015 JBoss by Red Hat | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* 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 org.kie.jenkinsci.plugins.kieprbuildshelper; | ||
|
||
public class GitHubRepository { | ||
private final String owner; | ||
private final String name; | ||
|
||
public GitHubRepository(String owner, String name) { | ||
this.owner = owner; | ||
this.name = name; | ||
} | ||
|
||
public String getOwner() { | ||
return owner; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getReadOnlyCloneURL() { | ||
return "git://github.com/" + owner + "/" + name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "GitHubRepository{" + | ||
"owner='" + owner + '\'' + | ||
", name='" + name + '\'' + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
GitHubRepository that = (GitHubRepository) o; | ||
|
||
if (owner != null ? !owner.equals(that.owner) : that.owner != null) return false; | ||
return !(name != null ? !name.equals(that.name) : that.name != null); | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = owner != null ? owner.hashCode() : 0; | ||
result = 31 * result + (name != null ? name.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/org/kie/jenkinsci/plugins/kieprbuildshelper/GitHubRepositoryList.java
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,62 @@ | ||
/* | ||
* Copyright 2015 JBoss by Red Hat | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* 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 org.kie.jenkinsci.plugins.kieprbuildshelper; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class GitHubRepositoryList { | ||
public static String KIE_REPO_LIST_MASTER_RESOURCE_PATH = "/repository-list-master.txt"; | ||
public static String KIE_REPO_LIST_6_3_X_RESOURCE_PATH = "/repository-list-6.3.x.txt"; | ||
public static String KIE_REPO_LIST_6_2_X_RESOURCE_PATH = "/repository-list-6.2.x.txt"; | ||
|
||
private final List<GitHubRepository> list; | ||
|
||
public static GitHubRepositoryList fromClasspathResource(String resourcePath) { | ||
InputStream is = GitHubRepositoryList.class.getResourceAsStream(resourcePath); | ||
if (is == null) { | ||
throw new IllegalArgumentException("Specified classpath resource '" + resourcePath + "' does not exist!"); | ||
} | ||
List<String> lines; | ||
try { | ||
lines = IOUtils.readLines(is); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Error while reading data from classpath resource '" + resourcePath + "'!", e); | ||
} | ||
List<GitHubRepository> repoList = new ArrayList<GitHubRepository>(); | ||
for (String line : lines) { | ||
String[] parts = line.split("/"); | ||
repoList.add(new GitHubRepository(parts[0], parts[1])); | ||
} | ||
return new GitHubRepositoryList(repoList); | ||
} | ||
|
||
public GitHubRepositoryList(List<GitHubRepository> list) { | ||
this.list = list; | ||
} | ||
|
||
public List<GitHubRepository> getList() { | ||
return list; | ||
} | ||
|
||
public int size() { | ||
return list.size(); | ||
} | ||
} |
Oops, something went wrong.