Skip to content

Commit

Permalink
fix bug about issue event max-number(30->3000)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosyrain committed Sep 3, 2024
1 parent 1e7fb74 commit 47f717b
Showing 1 changed file with 44 additions and 33 deletions.
77 changes: 44 additions & 33 deletions actions/reopen-without-PR/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,43 +189,54 @@ func main() {

// 1.获取issue时间线判断是否存在pr
// 构建请求URL
issueURL := fmt.Sprintf("%s/repos/%s/issues/%d/timeline", baseURL, repo, issueNumber)

// 创建请求头,包含认证信息
issueResp, err := ihttp.Request("GET", issueURL, token, nil, "")
if err != nil {
panic(fmt.Sprintf("issueUrl http.Request failed,err:%v", err))
}
if issueResp.StatusCode != http.StatusOK {
panic(fmt.Sprintf("connect issueUrl failed,resp.statusCode:%d", issueResp.StatusCode))
}
defer issueResp.Body.Close()
fmt.Printf("get issue %d info successfully.\n", issueNumber)
for page := 1; page <= 100; page++ {
fmt.Printf("get issue info,page=%d,per_page=30\n", page)
issueURL := fmt.Sprintf("%s/repos/%s/issues/%d/timeline?page=%d&per_page=30", baseURL, repo, issueNumber, page)

// 创建请求头,包含认证信息
issueResp, err := ihttp.Request("GET", issueURL, token, nil, "")
if err != nil {
panic(fmt.Sprintf("issueUrl http.Request failed,err:%v", err))
}
if issueResp.StatusCode != http.StatusOK {
panic(fmt.Sprintf("connect issueUrl failed,resp.statusCode:%d", issueResp.StatusCode))
}
defer issueResp.Body.Close()
fmt.Printf("get issue %d info successfully.\n", issueNumber)

// 解析响应内容(这里省略了具体的解析过程,你可以根据需要自行处理)
// 检查issue是否有关联的pull request
body, err := io.ReadAll(issueResp.Body)
if err != nil {
panic(fmt.Sprintf("Error reading issue response body:%v", err))
}
var issueData []interface{}
err = json.Unmarshal(body, &issueData)
if err != nil {
panic(fmt.Sprintf("Error unmarshalling JSON:%v", err))
}

// 解析响应内容(这里省略了具体的解析过程,你可以根据需要自行处理)
// 检查issue是否有关联的pull request
body, err := io.ReadAll(issueResp.Body)
if err != nil {
panic(fmt.Sprintf("Error reading issue response body:%v", err))
}
var issueData []interface{}
err = json.Unmarshal(body, &issueData)
if err != nil {
panic(fmt.Sprintf("Error unmarshalling JSON:%v", err))
}
// 如果获取到到数据为空,则说明已经全部获取了,退出循环
if len(issueData) == 0 {
break
}

for _, data := range issueData {
dataMap := data.(map[string]interface{})
typeEvent := dataMap["event"]
if typeEvent == "cross-referenced" {
sourceMap := dataMap["source"].(map[string]interface{})
issueMap := sourceMap["issue"].(map[string]interface{})
_, ok := issueMap["pull_request"]
if ok {
hasRelatedPR = true
break
for _, data := range issueData {
dataMap := data.(map[string]interface{})
typeEvent := dataMap["event"]
if typeEvent == "cross-referenced" {
sourceMap := dataMap["source"].(map[string]interface{})
issueMap := sourceMap["issue"].(map[string]interface{})
_, ok := issueMap["pull_request"]
if ok {
hasRelatedPR = true
break
}
}
}
if hasRelatedPR {
break
}
}

//3.进行加标签转交指定人员
Expand Down

0 comments on commit 47f717b

Please sign in to comment.