java中通过JIRA REST Java Client 使用jira

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

java中通过JIRA REST Java Client 使用jira

努力为了梦想   2020-03-11 我要评论

首先创建springboot工程,使用maven进行构建,pom依赖如下:

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

  加入依赖以后可以通过asynchronousJiraRestClientFactory进行登陆获取认证,本次使用用户名密码的方式进行校验,也可以使用其他 的方式进行校验(例如token的方式),登陆验证以后获取到jiraRestClient进行后续的操作。

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

  通过查看接口可以看到可以获取到多种操作类型的client。

public interface JiraRestClient extends Closeable {
    IssueRestClient getIssueClient();

    SessionRestClient getSessionClient();

    UserRestClient getUserClient();

    GroupRestClient getGroupClient();

    ProjectRestClient getProjectClient();

    ComponentRestClient getComponentClient();

    MetadataRestClient getMetadataClient();

    SearchRestClient getSearchClient();

    VersionRestClient getVersionRestClient();

    ProjectRolesRestClient getProjectRolesRestClient();

    AuditRestClient getAuditRestClient();

    MyPermissionsRestClient getMyPermissionsRestClient();

    void close() throws IOException;
}

  简单示例获取对应的issue信息

 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可以进行的操作上边已经已经注释。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们