Skip to content

Commit ab0c939

Browse files
committed
Made everything repo ready
1 parent c59b0ea commit ab0c939

File tree

4 files changed

+70
-35
lines changed

4 files changed

+70
-35
lines changed

pom.xml

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,60 @@
11
<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">
22
<modelVersion>4.0.0</modelVersion>
3+
34
<parent>
45
<groupId>org.jenkins-ci.plugins</groupId>
56
<artifactId>plugin</artifactId>
6-
<version>1.580</version><!-- which version of Jenkins is this plugin built against? -->
7+
<version>2.4</version>
78
</parent>
9+
<groupId>org.jenkins-ci.plugins</groupId>
10+
<artifactId>gogs-webhook</artifactId>
11+
<version>1.0.0</version>
12+
<packaging>hpi</packaging>
813

9-
<developers>
10-
<developer>
11-
<id>sanderv32</id>
12-
<name>Alexander Verhaar</name>
13-
</developer>
14-
</developers>
14+
<properties>
15+
<jenkins.version>1.625.3</jenkins.version>
16+
<java.level>7</java.level>
17+
<jenkins-test-harness.version>2.1</jenkins-test-harness.version>
18+
<additionalparam>-Xdoclint:none</additionalparam>
19+
</properties>
20+
21+
<name>Jenkins Gogs plugin</name>
22+
<description>Adds Gogs integration to Jenkins</description>
23+
<url>https://github.com/jenkinsci/gogs-webhook-plugin.git</url>
1524

1625
<licenses>
1726
<license>
18-
<name>MIT</name>
27+
<name>The MIT license</name>
1928
<url>http://www.opensource.org/licenses/mit-license.php</url>
29+
<distribution>repo</distribution>
2030
</license>
2131
</licenses>
2232

23-
<groupId>org.jenkins-ci.plugins</groupId>
24-
<artifactId>gogs-webhook</artifactId>
25-
<version>0.8.45</version>
26-
<packaging>hpi</packaging>
27-
<name>Jenkins Gogs plugin</name>
28-
<description>Adds Gogs integration to Jenkins</description>
29-
<url>https://github.com/sanderv32/gogs-webhook-plugin.git</url>
33+
<developers>
34+
<developer>
35+
<id>sanderv32</id>
36+
<name>Alexander Verhaar</name>
37+
</developer>
38+
</developers>
3039

3140
<dependencies>
41+
<dependency>
42+
<groupId>org.jenkins-ci.main</groupId>
43+
<artifactId>jenkins-war</artifactId>
44+
<type>war</type>
45+
<version>${jenkins.version}</version>
46+
<scope>test</scope>
47+
</dependency>
3248
<dependency>
3349
<groupId>org.jenkins-ci.plugins</groupId>
3450
<artifactId>git</artifactId>
3551
<version>2.2.5</version>
3652
</dependency>
53+
<dependency>
54+
<groupId>org.apache.httpcomponents</groupId>
55+
<artifactId>httpclient</artifactId>
56+
<version>4.5.1</version>
57+
</dependency>
3758
</dependencies>
3859

3960
<!-- get every artifact through repo.jenkins-ci.org, which proxies all the artifacts that we need -->
@@ -52,9 +73,9 @@
5273
</pluginRepositories>
5374

5475
<scm>
55-
<connection>scm:git:git://github.com/sanderv32/${project.artifctId}-plugin.git</connection>
56-
<developerConnection>scm:git:git@github.com:sanderv32/${project.artifactId}-plugin.git</developerConnection>
57-
<url>http://github.com/sanderv32/${project.artifactId}-plugin</url>
76+
<connection>scm:git:git://github.com/jenkinsci/${project.artifctId}-plugin.git</connection>
77+
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
78+
<url>http://github.com/jenkinsci/${project.artifactId}-plugin</url>
5879
<tag>HEAD</tag>
5980
</scm>
6081
</project>

src/main/java/org/jenkinsci/plugins/gogs/GogsPayloadProcessor.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ associated documentation files (the "Software"), to deal in the Software without
3232
import hudson.security.ACL;
3333
import hudson.model.AbstractProject;
3434
import jenkins.model.Jenkins;
35-
import hudson.model.Cause;
3635

3736
import org.acegisecurity.context.SecurityContext;
3837
import org.acegisecurity.context.SecurityContextHolder;
@@ -44,25 +43,36 @@ public GogsPayloadProcessor() {
4443
}
4544

4645
public GogsResults triggerJobs(String jobName, String deliveryID) {
46+
SecurityContext saveCtx = null;
4747
Boolean didJob = false;
4848
GogsResults result = new GogsResults();
4949

50-
SecurityContext old = Jenkins.getInstance().getACL().impersonate(ACL.SYSTEM);
51-
for (AbstractProject<?,?> project : Jenkins.getInstance().getAllItems(AbstractProject.class)) {
52-
if ( project.getName().equals(jobName) ) {
50+
try {
51+
saveCtx = SecurityContextHolder.getContext();
52+
53+
Jenkins instance = Jenkins.getInstance();
54+
if (instance!=null) {
55+
ACL acl = instance.getACL();
56+
acl.impersonate(ACL.SYSTEM);
57+
for (AbstractProject<?,?> project : instance.getAllItems(AbstractProject.class)) {
58+
if ( project.getName().equals(jobName) ) {
5359

54-
Cause cause = new GogsCause(deliveryID);
55-
project.scheduleBuild(0, cause);
56-
didJob = true;
57-
result.setMessage(String.format("Job '%s' is executed",jobName));
60+
Cause cause = new GogsCause(deliveryID);
61+
project.scheduleBuild(0, cause);
62+
didJob = true;
63+
result.setMessage(String.format("Job '%s' is executed",jobName));
64+
}
65+
}
66+
if (!didJob) {
67+
String msg = String.format("Job '%s' is not defined in Jenkins",jobName);
68+
result.setStatus(404, msg);
69+
LOGGER.warning(msg);
70+
}
5871
}
72+
} catch (Exception e) {
73+
} finally {
74+
SecurityContextHolder.setContext(saveCtx);
5975
}
60-
if (!didJob) {
61-
String msg = String.format("Job '%s' is not defined in Jenkins",jobName);
62-
result.setStatus(404, msg);
63-
LOGGER.warning(msg);
64-
}
65-
SecurityContextHolder.setContext(old);
6676

6777
return result;
6878
}

src/main/java/org/jenkinsci/plugins/gogs/GogsWebHook.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ public String getUrlName() {
7777
* Receives the HTTP POST request send by Gogs.
7878
*
7979
* @param req request
80-
* @return response to the request
8180
*/
8281
public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException {
82+
String url = null;
8383
GogsResults result = new GogsResults();
8484
GogsPayloadProcessor payloadProcessor = new GogsPayloadProcessor();
8585
GogsProjectProperty.DescriptorImpl projectProperty = jenkins.getDescriptorByType(GogsProjectProperty.DescriptorImpl.class);
@@ -94,7 +94,7 @@ public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException
9494

9595
// Get X-Gogs-Delivery header with deliveryID
9696
String gogsDelivery = req.getHeader("X-Gogs-Delivery");
97-
if ( gogsDelivery==null && gogsDelivery.isEmpty() ) {
97+
if ( gogsDelivery==null || gogsDelivery.isEmpty() ) {
9898
gogsDelivery = "Triggered by Jenkins-Gogs-Plugin. Delivery ID unknown.";
9999
} else {
100100
gogsDelivery = "Gogs-ID: " + gogsDelivery;
@@ -122,7 +122,10 @@ public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException
122122
JSONObject jsonObject = JSONObject.fromObject(body);
123123
String gSecret = jsonObject.getString("secret"); /* Secret provided by Gogs */
124124
String jSecret = projectProperty.getGogsSecret(); /* Secret provided by Jenkins */
125-
String url = jsonObject.getJSONObject("repository").getString("url");
125+
// JSONObject repo = jsonObject.getJSONObject("repository");
126+
// if (repo!=null) {
127+
// url = repo.getString("url");
128+
// }
126129

127130
if ( gSecret!=null && !gSecret.isEmpty() ) {
128131
/* Gogs secret is set */

src/main/resources/index.jelly

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?jelly escape-by-default='true'?>
12
<div>
23
This plugin adds Gogs integration to Jenkins.
34
</div>

0 commit comments

Comments
 (0)