Author: olamy Date: Sat Nov 26 22:50:03 2011 New Revision: 1206627 URL: http://svn.apache.org/viewvc?rev=1206627&view=rev Log: mojo to create a jira issue from a pull request
Added: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/PullRequestToJiraMojo.java (with props) maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/PullRequest.java (with props) Modified: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/pom.xml maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java Modified: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/pom.xml URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/pom.xml?rev=1206627&r1=1206626&r2=1206627&view=diff ============================================================================== --- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/pom.xml (original) +++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/pom.xml Sat Nov 26 22:50:03 2011 @@ -146,6 +146,29 @@ under the License. </dependency> <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-mapper-asl</artifactId> + <version>1.9.2</version> + </dependency> + + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>4.1.2</version> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpcore</artifactId> + <version>4.1.2</version> + </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.0.1</version> + </dependency> + + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> Modified: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java?rev=1206627&r1=1206626&r2=1206627&view=diff ============================================================================== --- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java (original) +++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/AbstractPatchMojo.java Sat Nov 26 22:50:03 2011 @@ -34,10 +34,14 @@ import org.apache.maven.scm.repository.S import org.apache.maven.scm.repository.ScmRepositoryException; import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; +import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.components.interactivity.Prompter; import org.codehaus.plexus.components.interactivity.PrompterException; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import java.io.File; import java.util.Arrays; @@ -49,6 +53,7 @@ import java.util.List; */ public abstract class AbstractPatchMojo extends AbstractMojo + implements Contextualizable { /** * The Maven Project Object. @@ -142,9 +147,6 @@ public abstract class AbstractPatchMojo */ protected Prompter prompter; - /** - * @component - */ protected PlexusContainer plexusContainer; /** @@ -418,4 +420,10 @@ public abstract class AbstractPatchMojo return (PatchTracker) plexusContainer.lookup( PatchTracker.class.getName(), system ); } + + public void contextualize( Context context ) + throws ContextException + { + this.plexusContainer = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + } } Added: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/PullRequestToJiraMojo.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/PullRequestToJiraMojo.java?rev=1206627&view=auto ============================================================================== --- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/PullRequestToJiraMojo.java (added) +++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/PullRequestToJiraMojo.java Sat Nov 26 22:50:03 2011 @@ -0,0 +1,148 @@ +package org.apache.maven.plugins.patchtracker; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.patchtracker.github.PullRequest; +import org.apache.maven.plugins.patchtracker.tracking.PatchTracker; +import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerException; +import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerRequest; +import org.apache.maven.plugins.patchtracker.tracking.PatchTrackerResult; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +import java.io.IOException; + + +/** + * @author Olivier Lamy + * @goal create-issue-from-patch-request + * @aggregator + */ +public class PullRequestToJiraMojo + extends AbstractPatchMojo +{ + + /** + * github user/organization : github.com/apache use apache + * + * @parameter expression="${patch.pullrequest.user}" default-value="" + */ + protected String user; + + /** + * github repo : github.com/apache/maven-3 use maven-3 + * + * @parameter expression="${patch.pullrequest.repo}" default-value="" + */ + protected String repo; + + /** + * pull request id + * + * @parameter expression="${patch.pullrequest.id}" default-value="" + */ + protected String pullRequestId; + + + /** + * github api url + * + * @parameter expression="${patch.pullrequest.githubApiUrl}" default-value="https://api.github.com/repos" + */ + protected String githubApiUrl; + + + DefaultHttpClient defaultHttpClient = new DefaultHttpClient(); + + public void execute() + throws MojoExecutionException, MojoFailureException + { + // format curl -v https://api.github.com/repos/apache/directmemory/pulls/1 + try + { + + String url = githubApiUrl + "/" + user + "/" + repo + "/pulls/" + pullRequestId; + getLog().debug( "url" + url ); + + HttpGet httpGet = new HttpGet( url ); + + HttpResponse httpResponse = defaultHttpClient.execute( httpGet ); + + ObjectMapper objectMapper = new ObjectMapper(); + + // we don't parse all stuff + objectMapper.configure( DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false ); + + String response = IOUtils.toString( httpResponse.getEntity().getContent() ); + + getLog().debug( "response:" + response ); + + PullRequest pullRequest = objectMapper.reader( PullRequest.class ).readValue( response ); + + getLog().debug( "pullRequest:" + pullRequest.toString() ); + + PatchTrackerRequest patchTrackerRequest = buidPatchTrackerRequest( false ); + + patchTrackerRequest.setSummary( pullRequest.getTitle() ); + + patchTrackerRequest.setDescription( pullRequest.getBody() + ". url: " + pullRequest.getPatch_url() ); + + patchTrackerRequest.setPatchContent( getPatchContent( pullRequest ) ); + + PatchTracker patchTracker = getPatchTracker(); + + PatchTrackerResult result = patchTracker.createPatch( patchTrackerRequest ); + getLog().info( "issue created with id:" + result.getPatchId() + ", url:" + result.getPatchUrl() ); + } + catch ( ClientProtocolException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + catch ( ComponentLookupException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + catch ( PatchTrackerException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + } + + protected String getPatchContent( PullRequest pullRequest ) + throws IOException, ClientProtocolException + { + HttpGet httpGet = new HttpGet( pullRequest.getPatch_url() ); + + HttpResponse httpResponse = defaultHttpClient.execute( httpGet ); + + return IOUtils.toString( httpResponse.getEntity().getContent() ); + } +} Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/PullRequestToJiraMojo.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/PullRequestToJiraMojo.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/PullRequest.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/PullRequest.java?rev=1206627&view=auto ============================================================================== --- maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/PullRequest.java (added) +++ maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/PullRequest.java Sat Nov 26 22:50:03 2011 @@ -0,0 +1,231 @@ +package org.apache.maven.plugins.patchtracker.github; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import java.io.Serializable; + +/** + * @author Olivier Lamy + */ +public class PullRequest + implements Serializable +{ + /** + * json format + * <p/> + * curl -v https://api.github.com/repos/apache/directmemory/pulls/1 + * <p/> + * { + * "merged_by": null, + * "merged": false, + * "title": "test wonderful patch ", + * "head": { + * "repo": { + * "watchers": 1, + * "forks": 0, + * "pushed_at": "2011-11-26T15:17:32Z", + * "svn_url": "https://svn.github.com/olamy/directmemory", + * "description": "Mirror of Apache DirectMemory", + * "created_at": "2011-11-26T09:39:35Z", + * "url": "https://api.github.com/repos/olamy/directmemory", + * "fork": true, + * "language": "Java", + * "git_url": "git://github.com/olamy/directmemory.git", + * "clone_url": "https://github.com/olamy/directmemory.git", + * "open_issues": 0, + * "private": false, + * "html_url": "https://github.com/olamy/directmemory", + * "homepage": null, + * "size": 112, + * "master_branch": "trunk", + * "updated_at": "2011-11-26T15:17:32Z", + * "owner": { + * "avatar_url": "https://secure.gravatar.com/avatar/bab29f762bea8e578505424443d8cd41?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", + * "url": "https://api.github.com/users/olamy", + * "login": "olamy", + * "gravatar_id": "bab29f762bea8e578505424443d8cd41", + * "id": 19728 + * }, + * "name": "directmemory", + * "id": 2854963, + * "ssh_url": "g...@github.com:olamy/directmemory.git" + * }, + * "user": { + * "avatar_url": "https://secure.gravatar.com/avatar/bab29f762bea8e578505424443d8cd41?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", + * "url": "https://api.github.com/users/olamy", + * "login": "olamy", + * "gravatar_id": "bab29f762bea8e578505424443d8cd41", + * "id": 19728 + * }, + * "ref": "trunk", + * "label": "olamy:trunk", + * "sha": "73d403199b415108a6f2a72c95b9ec684e6f1dc1" + * }, + * "_links": { + * "html": { + * "href": "https://github.com/apache/directmemory/pull/1" + * }, + * "review_comments": { + * "href": "https://api.github.com/repos/apache/directmemory/pulls/1/comments" + * }, + * "self": { + * "href": "https://api.github.com/repos/apache/directmemory/pulls/1" + * }, + * "comments": { + * "href": "https://api.github.com/repos/apache/directmemory/issues/1/comments" + * } + * }, + * "merged_at": null, + * "created_at": "2011-11-26T14:59:52Z", + * "state": "open", + * "url": "https://api.github.com/repos/apache/directmemory/pulls/1", + * "commits": 3, + * "deletions": 0, + * "changed_files": 2, + * "review_comments": 0, + * "closed_at": null, + * "user": { + * "avatar_url": "https://secure.gravatar.com/avatar/bab29f762bea8e578505424443d8cd41?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", + * "url": "https://api.github.com/users/olamy", + * "login": "olamy", + * "gravatar_id": "bab29f762bea8e578505424443d8cd41", + * "id": 19728 + * }, + * "base": { + * "repo": { + * "watchers": 3, + * "forks": 2, + * "pushed_at": "2011-11-03T00:02:25Z", + * "svn_url": "https://svn.github.com/apache/directmemory", + * "description": "Mirror of Apache DirectMemory", + * "created_at": "2011-10-15T07:00:08Z", + * "url": "https://api.github.com/repos/apache/directmemory", + * "fork": false, + * "language": "Java", + * "git_url": "git://github.com/apache/directmemory.git", + * "clone_url": "https://github.com/apache/directmemory.git", + * "open_issues": 0, + * "private": false, + * "html_url": "https://github.com/apache/directmemory", + * "homepage": null, + * "size": 3076, + * "master_branch": "trunk", + * "updated_at": "2011-11-26T09:39:35Z", + * "owner": { + * "avatar_url": "https://secure.gravatar.com/avatar/a676c0bf448fcd49f588249ead719b4c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", + * "url": "https://api.github.com/users/apache", + * "login": "apache", + * "gravatar_id": "a676c0bf448fcd49f588249ead719b4c", + * "id": 47359 + * }, + * "name": "directmemory", + * "id": 2580771, + * "ssh_url": "g...@github.com:apache/directmemory.git" + * }, + * "user": { + * "avatar_url": "https://secure.gravatar.com/avatar/a676c0bf448fcd49f588249ead719b4c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", + * "url": "https://api.github.com/users/apache", + * "login": "apache", + * "gravatar_id": "a676c0bf448fcd49f588249ead719b4c", + * "id": 47359 + * }, + * "ref": "trunk", + * "label": "apache:trunk", + * "sha": "f9ddc283dbc4f391a0876b5bd36453ac7e563b79" + * }, + * "html_url": "https://github.com/apache/directmemory/pull/1", + * "updated_at": "2011-11-26T15:17:33Z", + * "number": 1, + * "issue_url": "https://github.com/apache/directmemory/issues/1", + * "mergeable": true, + * "additions": 6, + * "patch_url": "https://github.com/apache/directmemory/pull/1.patch", + * "id": 530496, + * "comments": 0, + * "body": "test email works to directmemory ml .", + * "diff_url": "https://github.com/apache/directmemory/pull/1.diff" + * } + */ + + private String title; + + private String html_url; + + private String patch_url; + + private String body; + + public PullRequest() + { + // no op + } + + public String getTitle() + { + return title; + } + + public void setTitle( String title ) + { + this.title = title; + } + + public String getHtml_url() + { + return html_url; + } + + public void setHtml_url( String html_url ) + { + this.html_url = html_url; + } + + public String getPatch_url() + { + return patch_url; + } + + public void setPatch_url( String patch_url ) + { + this.patch_url = patch_url; + } + + public String getBody() + { + return body; + } + + public void setBody( String body ) + { + this.body = body; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "PullRequest" ); + sb.append( "{title='" ).append( title ).append( '\'' ); + sb.append( ", html_url='" ).append( html_url ).append( '\'' ); + sb.append( ", patch_url='" ).append( patch_url ).append( '\'' ); + sb.append( ", body='" ).append( body ).append( '\'' ); + sb.append( '}' ); + return sb.toString(); + } +} Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/PullRequest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/sandbox/trunk/plugins/maven-patch-tracker-plugin/src/main/java/org/apache/maven/plugins/patchtracker/github/PullRequest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision