Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Forked from jvanzyl/gist:6055789
Created July 22, 2013 17:49
Show Gist options
  • Save sunnygleason/6055969 to your computer and use it in GitHub Desktop.
Save sunnygleason/6055969 to your computer and use it in GitHub Desktop.
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