-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
239 additions
and
88 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
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
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
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
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
122 changes: 122 additions & 0 deletions
122
src/main/java/com/uber/jenkins/phabricator/conduit/DifferentialClient.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,122 @@ | ||
// Copyright (c) 2015 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package com.uber.jenkins.phabricator.conduit; | ||
|
||
import com.uber.jenkins.phabricator.LauncherFactory; | ||
import net.sf.json.JSONException; | ||
import net.sf.json.JSONObject; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* DifferentialClient handles all interaction with conduit/arc for differentials | ||
*/ | ||
public class DifferentialClient { | ||
private final String arcPath; | ||
private final String conduitToken; | ||
private final LauncherFactory launcher; | ||
private final String diffID; | ||
|
||
public DifferentialClient(String diffID, LauncherFactory launcher, String conduitToken, String arcPath) { | ||
this.diffID = diffID; | ||
this.launcher = launcher; | ||
this.conduitToken = conduitToken; | ||
this.arcPath = arcPath; | ||
} | ||
|
||
/** | ||
* Posts a comment to a differential | ||
* @param message | ||
* @param silent whether or not to trigger an email | ||
* @param action phabricator comment action, e.g. 'resign', 'reject', 'none' | ||
*/ | ||
public JSONObject postComment(String message, boolean silent, String action) throws IOException, InterruptedException, ArcanistUsageException { | ||
Map params = new HashMap<String, String>(); | ||
params.put("revision_id", this.diffID); | ||
params.put("action", action); | ||
params.put("message", message); | ||
params.put("silent", silent); | ||
|
||
return this.callConduit("differential.createcomment", params); | ||
} | ||
|
||
public JSONObject fetchDiff() throws ArcanistUsageException, IOException, InterruptedException { | ||
Map params = new HashMap<String, String>(); | ||
params.put("ids", new String[]{this.diffID}); | ||
JSONObject query = this.callConduit("differential.querydiffs", params); | ||
JSONObject response; | ||
try { | ||
response = query.getJSONObject("response"); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
throw new ArcanistUsageException( | ||
String.format("No 'response' object found in conduit call: (%s) %s", | ||
e.getMessage(), | ||
query.toString(2))); | ||
} | ||
try { | ||
return response.getJSONObject(diffID); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
throw new ArcanistUsageException( | ||
String.format("Unable to find '%s' key in response: (%s) %s", | ||
diffID, | ||
e.getMessage(), | ||
response.toString(2))); | ||
|
||
} | ||
} | ||
|
||
protected JSONObject callConduit(String methodName, Map<String, String> params) throws IOException, InterruptedException, ArcanistUsageException { | ||
ArcanistClient arc = new ArcanistClient(this.arcPath, "call-conduit", params, this.conduitToken, methodName); | ||
return arc.parseConduit(this.launcher.launch(), this.launcher.getStderr()); | ||
} | ||
|
||
/** | ||
* Sets a harbormaster build status | ||
* @param phid Phabricator object ID | ||
* @param pass whether or not the build passed | ||
* @throws IOException | ||
* @throws InterruptedException | ||
*/ | ||
public void harbormaster(String phid, boolean pass) throws IOException, InterruptedException, ArcanistUsageException { | ||
Map params = new HashMap<String, String>(); | ||
params.put("type", pass ? "pass" : "fail"); | ||
params.put("buildTargetPHID", phid); | ||
|
||
this.callConduit("harbormaster.sendmessage", params); | ||
} | ||
|
||
|
||
/** | ||
* Post a comment on the differential | ||
* @param message the string message to post | ||
* @return | ||
* @throws IOException | ||
* @throws InterruptedException | ||
* @throws ArcanistUsageException | ||
*/ | ||
public JSONObject postComment(String message) throws IOException, InterruptedException, ArcanistUsageException { | ||
return postComment(message, true, "none"); | ||
} | ||
} |
Oops, something went wrong.