簡體   English   中英

如何檢索Java Web應用程序的更改列表?

[英]How can I retrieve a list of changes for my Java web app?

我有一個Spring Boot應用程序,我想有一個頁面,其中列出了最近的內部版本號及其包含的更改列表。 我使用了Rally,git和Jenkins,但是沒有手動更新HTML或db表,我想知道是否沒有一種更自動化的方法來檢索此信息?

任何人都可以在應用程序中分享其在網頁上列出此信息的方法嗎?

如果您在Jenkins中將/api/json?pretty=true附加到作業URL的末尾,您會看到作業本身的JSON輸出,這可能會導致您獲得最新的內部版本號。 此外,這會將您帶到最新版本的URL,(再次附加/api/json?pretty=true )可以將您帶到變更集的JSON列表(以及相應的提交消息)。

您甚至可能不需要利用Rally! :-)

您可以使用JSON封送和RestTemplate Spring類從Spring應用程序中使用該JSON。

您可以通過使用Git連接器Jenkins插件 (只要兩者都指向同一存儲庫)來跟蹤從git提交到關聯的CA AgileCentral(Rally)工件的成功和失敗的Jenkins構建,只要兩者都指向同一存儲庫,並且git中的提交提到相關工件的FormattedID。

這是一個基於Rally API Toolkit For Java的Java示例。 無論選擇什么工具包,語言等等,都是通過底層WS API對象模型提供對這些數據的訪問。 我通過CreationDate限制了構建查詢。 在Build對象的其他字段中,我獲取Changesets集合。 該集合的每個元素都是對Changeset對象的引用。 Git連接器在CA Agile Central(Rally)中創建更改集對象。 每個Changeset對象都有Artfacts集合字段和Changes集合字段。 Artifacts集合的每個元素都是對Rally工件的引用,例如用戶故事,缺陷。 通過在每個Change對象上獲取PathAndFilename,您將獲得關聯的源文件。 現在,我們可以將失敗的構建跟蹤到特定的提交,文件和用戶故事。

這是下面的Java代碼創建的控制台輸出的屏幕截圖。 最終,您可能希望以一種更具視覺吸引力的方式呈現數據。 該示例僅顯示可以通過WS API跟蹤構建和提交到用戶案例或缺陷。

通常需要單獨的請求來混合WS API中的集合 由於Build和Cangesets數據可能很大,因此請按某些條件綁定這些查詢,例如CreationDate將使其更快。

在此處輸入圖片說明

public class GetBuildData {

    public static void main(String[] args) throws Exception {

        String host = "https://rally1.rallydev.com";
        String apiKey = "_abc123"; 
        String applicationName = "NickM:GetBuildData";
        String workspaceRef = "/workspace/12345";
        String projectRef = "/project/1346";

        RallyRestApi restApi = null;
        try {
            String dateString = "2016-05-12";
            restApi = new RallyRestApi(new URI(host),apiKey);
            restApi.setApplicationName(applicationName);
            QueryRequest buildRequest = new QueryRequest("Build");
            buildRequest.setFetch(new Fetch("Status,Message,Start,Uri,Changesets"));
            buildRequest.setQueryFilter(new QueryFilter("CreationDate", ">", dateString));
            buildRequest.setWorkspace(workspaceRef);
            buildRequest.setProject(projectRef);
            QueryResponse buildResponse = restApi.query(buildRequest);
            for (int i=0; i<buildResponse.getTotalResultCount();i++){
                JsonObject buildObj = buildResponse.getResults().get(i).getAsJsonObject();
                System.out.println("Build Status: " + buildObj.get("Status") +
                        "\n Build Message: " + buildObj.get("Message") +
                        "\n Build Start:   " + buildObj.get("Start") +
                        "\n Build Uri:     " + buildObj.get("Uri"));
                JsonObject changesetsCollection = buildObj.get("Changesets").getAsJsonObject();
                QueryRequest changesetsRequest = new QueryRequest(changesetsCollection);
                changesetsRequest.setFetch(new Fetch("Artifacts","Changes", "Revision"));
                changesetsRequest.setLimit(1000);
                QueryResponse changesetsResponse = restApi.query(changesetsRequest);
                for (int j=0; j<changesetsResponse.getTotalResultCount();j++) {
                    JsonObject changesetObj = changesetsResponse.getResults().get(j).getAsJsonObject();
                    System.out.println("\nChangeset Revision: " + changesetObj.get("Revision"));
                    JsonObject artifactsCollection = changesetObj.get("Artifacts").getAsJsonObject();
                    QueryRequest artifactsRequest = new QueryRequest(artifactsCollection);
                    artifactsRequest.setFetch(new Fetch("FormattedID"));
                    QueryResponse artifactsResponse = restApi.query(artifactsRequest);
                    for (int k=0; k<artifactsResponse.getTotalResultCount();k++) {
                        JsonObject artifactObj = artifactsResponse.getResults().get(k).getAsJsonObject();
                        System.out.println("\nArtifact FormattedID: " + artifactObj.get("FormattedID"));
                    }
                    JsonObject changesCollection = changesetObj.get("Changes").getAsJsonObject();
                    QueryRequest changesRequest = new QueryRequest(changesCollection);
                    changesRequest.setWorkspace(workspaceRef);
                    changesRequest.setProject(projectRef);
                    changesRequest.setFetch(new Fetch("PathAndFilename"));
                    QueryResponse changesResponse = restApi.query(changesRequest);
                    for (int l=0; l<changesResponse.getTotalResultCount();l++) {
                        JsonObject changeObj = changesResponse.getResults().get(l).getAsJsonObject();
                        System.out.println("Change PathAndFilename: " + changeObj.get("PathAndFilename"));
                    }

                }
                System.out.println("--------------------------------");
            }
        } finally {
            if (restApi != null) {
                restApi.close();
            }
        }
    }
}

如果要在Agile Central(拉力賽)中顯示構建數據,可以在自定義頁面中部署AppSDK2.1 javascript應用程序。 這是一個快速的示例開始:

    <!DOCTYPE html>
<html>
<head>
    <title>Builds by Date</title>
    <script type="text/javascript" src="/apps/2.1/sdk.js"></script>
    <script type="text/javascript">
        Rally.onReady(function () {
                Ext.define('CustomApp', {
    extend: 'Rally.app.App',
    componentCls: 'app',
    launch: function() {
        this.add({
            xtype: 'component',
            itemId: 'datepick',
            html: 'pick a date:',
            width: 100,
            margin: 10
        },
        {
            xtype: 'rallydatepicker',
            showToday: false,
            contentEl: Ext.ComponentQuery.query('#datepick')[0],
            margin: 10,
            handler: function(picker, date) {
                this.getBuilds(date);
            },
            scope:this
        },
        {
            xtype: 'container',
            itemId: 'gridContainer'
        });
    },
    getBuilds:function(date){
        var formattedDate = Rally.util.DateTime.formatWithDefault(date, this.getContext());
        Ext.ComponentQuery.query('#datepick')[0].update((formattedDate) + '<br /> selected');
        if (this.down('rallygrid')) {
            Ext.ComponentQuery.query('#gridContainer')[0].remove(Ext.ComponentQuery.query('#buildsGrid')[0], true);
        }
        this.down('#gridContainer').add({
            xtype: 'rallygrid',
            itemId: 'buildsGrid',
            columnCfgs: [
                'Status',
                'Message',
                'Start',
                'Uri',
                'Changesets'
            ],
            storeConfig: {
                model: 'build',
                filters:[
                    {
                        property: 'CreationDate',
                        operator: '>=',
                        value: Rally.util.DateTime.toIsoString(date,true)
                    }
                ]
            }
        });
    }
});
            Rally.launchApp('CustomApp', {
                name:"Builds by Date",
                parentRepos:""
            });
        });
    </script>
    <style type="text/css">
        .app {
  /* Add app styles here */
}
    </style>
</head>
<body>
</body>
</html>

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM