You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by GitBox <gi...@apache.org> on 2022/12/14 12:59:39 UTC

[GitHub] [incubator-devlake] mappjzc opened a new pull request, #3931: Jenkins jobs

mappjzc opened a new pull request, #3931:
URL: https://github.com/apache/incubator-devlake/pull/3931

   ### Summary
   Since we need compatibility with makePipelinePlanV100
   So we need Jenkins to get all the jobs when makePipelinePlanV100
   So we need a method to get all Jobs
   
   Now create the method GetAllJobs and the corresponding unit test.
   
   ### Does this close any open issues?
   Closes xx
   
   ### Screenshots
   ![image](https://user-images.githubusercontent.com/2921251/207600933-946c32cd-ba65-4c6f-b31f-11f97f0070d9.png)
   
   ### Other Information
   Any other information that is important to this PR.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh merged pull request #3931: Jenkins add GetAllJobs

Posted by GitBox <gi...@apache.org>.
likyh merged PR #3931:
URL: https://github.com/apache/incubator-devlake/pull/3931


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #3931: Jenkins add GetAllJobs

Posted by GitBox <gi...@apache.org>.
likyh commented on code in PR #3931:
URL: https://github.com/apache/incubator-devlake/pull/3931#discussion_r1049381515


##########
plugins/jenkins/api/jobs.go:
##########
@@ -0,0 +1,92 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package api
+
+import (
+	"encoding/json"
+	"fmt"
+	"net/http"
+	"net/url"
+
+	"github.com/apache/incubator-devlake/plugins/jenkins/models"
+
+	"github.com/apache/incubator-devlake/errors"
+	"github.com/apache/incubator-devlake/plugins/helper"
+)
+
+// request all jobs
+func GetAllJobs(apiClient helper.ApiClientGetter, path string, pageSize int, callback func(job *models.Job, isPath bool) errors.Error) errors.Error {
+	for i := 0; ; i += pageSize {
+		var data struct {
+			Jobs []json.RawMessage `json:"jobs"`
+		}
+
+		// set query
+		query := url.Values{}
+		treeValue := fmt.Sprintf("jobs[name,class,url,color,base,jobs,upstreamProjects[name]]{%d,%d}", i, i+pageSize)
+		query.Set("tree", treeValue)
+
+		res, err := apiClient.Get(path+"/api/json", query, nil)
+		if err != nil {
+			return err
+		}
+
+		err = helper.UnmarshalResponse(res, &data)
+		if err != nil {
+			// In some directories, after testing
+			// it is found that if the second page is empty, a 500 error will be returned.
+			// So we don't think it's an error to return 500 in this case
+			if i > 0 && res.StatusCode == http.StatusInternalServerError {
+				break
+			}
+			return err
+		}
+
+		for _, rawJobs := range data.Jobs {
+			job := &models.Job{}
+			err1 := json.Unmarshal(rawJobs, job)
+			if err1 != nil {
+				return errors.Convert(err1)
+			}
+
+			job.Path = path
+			job.FullName = path + job.Name

Review Comment:
   FullName should read from response.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-devlake] likyh commented on a diff in pull request #3931: Jenkins add GetAllJobs

Posted by GitBox <gi...@apache.org>.
likyh commented on code in PR #3931:
URL: https://github.com/apache/incubator-devlake/pull/3931#discussion_r1049381515


##########
plugins/jenkins/api/jobs.go:
##########
@@ -0,0 +1,92 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package api
+
+import (
+	"encoding/json"
+	"fmt"
+	"net/http"
+	"net/url"
+
+	"github.com/apache/incubator-devlake/plugins/jenkins/models"
+
+	"github.com/apache/incubator-devlake/errors"
+	"github.com/apache/incubator-devlake/plugins/helper"
+)
+
+// request all jobs
+func GetAllJobs(apiClient helper.ApiClientGetter, path string, pageSize int, callback func(job *models.Job, isPath bool) errors.Error) errors.Error {
+	for i := 0; ; i += pageSize {
+		var data struct {
+			Jobs []json.RawMessage `json:"jobs"`
+		}
+
+		// set query
+		query := url.Values{}
+		treeValue := fmt.Sprintf("jobs[name,class,url,color,base,jobs,upstreamProjects[name]]{%d,%d}", i, i+pageSize)
+		query.Set("tree", treeValue)
+
+		res, err := apiClient.Get(path+"/api/json", query, nil)
+		if err != nil {
+			return err
+		}
+
+		err = helper.UnmarshalResponse(res, &data)
+		if err != nil {
+			// In some directories, after testing
+			// it is found that if the second page is empty, a 500 error will be returned.
+			// So we don't think it's an error to return 500 in this case
+			if i > 0 && res.StatusCode == http.StatusInternalServerError {
+				break
+			}
+			return err
+		}
+
+		for _, rawJobs := range data.Jobs {
+			job := &models.Job{}
+			err1 := json.Unmarshal(rawJobs, job)
+			if err1 != nil {
+				return errors.Convert(err1)
+			}
+
+			job.Path = path
+			job.FullName = path + job.Name

Review Comment:
   FullName should read from response. Or use the path which has been deleted `job/`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org