java中經過JIRA REST Java Client 使用jira

首先建立springboot工程,使用maven進行構建,pom依賴以下:html

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
<!-- 使用jira-rest-cilent的依賴--> <dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-rest-java-client-core</artifactId> <version>5.1.6</version> </dependency> <dependency> <groupId>io.atlassian.fugue</groupId> <artifactId>fugue</artifactId> <version>4.7.2</version> <scope>provided</scope> </dependency> </dependencies>

  加入依賴之後能夠經過asynchronousJiraRestClientFactory進行登錄獲取認證,本次使用用戶名密碼的方式進行校驗,也能夠使用其餘 的方式進行校驗(例如token的方式),登錄驗證之後獲取到jiraRestClient進行後續的操做。java

public JiraRestClient loginJira(){
        AsynchronousJiraRestClientFactory asynchronousJiraRestClientFactory = new AsynchronousJiraRestClientFactory();
        JiraRestClient jiraRestClient = asynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(URI.create(jira地址), 用戶名,密碼);
        return jiraRestClient;
    }

  經過查看接口能夠看到能夠獲取到多種操做類型的client。web

public interface JiraRestClient extends Closeable {
    IssueRestClient getIssueClient(); //能夠進行issue相關的操做

    SessionRestClient getSessionClient();

    UserRestClient getUserClient(); //jira用戶相關的操做

    GroupRestClient getGroupClient();

    ProjectRestClient getProjectClient(); //工程相關的操做

    ComponentRestClient getComponentClient();

    MetadataRestClient getMetadataClient();

    SearchRestClient getSearchClient();

    VersionRestClient getVersionRestClient();

    ProjectRolesRestClient getProjectRolesRestClient();

    AuditRestClient getAuditRestClient();

    MyPermissionsRestClient getMyPermissionsRestClient();

    void close() throws IOException;
}

  簡單示例獲取對應的issue信息spring

Issue issue = jiraRestClient.getIssueClient().getIssue(此處是須要查詢的issuekey).claim();
        System.out.println(issue);
        System.out.println(issue.getStatus()+"+++++++++++++++++");
        System.out.println(issue.getStatus().getName()+"jira status ");

  其餘的操做都是獲取對應的client進行操做便可,對應client能夠進行的操做上邊已經已經註釋。springboot

原文出處:https://www.cnblogs.com/javasingle/p/12213783.htmlasync

相關文章
相關標籤/搜索