-
-
Save sunnygleason/6055969 to your computer and use it in GitHub Desktop.
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
package io.tesla.issues.jira; | |
import java.nio.charset.Charset; | |
import com.google.common.io.BaseEncoding; | |
import retrofit.RequestInterceptor; | |
import retrofit.RestAdapter; | |
public class JiraService { | |
private Jira service; | |
public JiraService(final String jiraServerUrl, final String username, final String password) { | |
final BaseEncoding base64 = BaseEncoding.base64(); | |
RequestInterceptor requestInterceptor = new RequestInterceptor() { | |
public void intercept(RequestFacade request) { | |
String authorization = username + ":" + password; | |
request.addHeader("Authorization", "Basic " + base64.encode(authorization.getBytes(Charset.forName("UTF-8")))); | |
} | |
}; | |
RestAdapter restAdapter = new RestAdapter.Builder() | |
.setServer(jiraServerUrl) | |
.setRequestInterceptor(requestInterceptor) | |
.setDebug(true) | |
.build(); | |
service = restAdapter.create(Jira.class); | |
} | |
public void createIssue(String projectKey, String summary, String description) { | |
service.createIssue(new JiraIssue(projectKey, summary, description)); | |
} | |
public static void main(String[] args) throws Exception { | |
JiraService js = new JiraService("https://issues.sonatype.org", "jvanzyl", "XXXXXX"); | |
js.createIssue("PR", "Summary", "Description"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment