Module: GetIssues

Defined in:
lib/get_issues.rb,
lib/get_issues/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.8"

Class Method Summary collapse

Class Method Details

.init_header_styleObject

定义xlsx文件格式的头样式



72
73
74
# File 'lib/get_issues.rb', line 72

def self.init_header_style
  { height: 75, background_color: "458B00", color: "FFFFFF", align: :center, font_name: "Arial", font_size: 14, bold: false, italic: false, underline: false }
end

.init_row_styleObject

定义xlsx文件的row样式



77
78
79
# File 'lib/get_issues.rb', line 77

def self.init_row_style
  { font_size: 12, align: :left }
end

.start_group(prefix_url, private_token, group_name, mile_stone_title) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/get_issues.rb', line 7

def self.start_group(prefix_url,private_token,group_name,mile_stone_title)
  groups_string = `curl --header "PRIVATE-TOKEN: #{private_token}" "#{prefix_url}/groups?per_page=1000"`
  groups_json = JSON.parse(groups_string)
  group_json = groups_json.filter { |t| t["name"] == group_name }&.first || {}
  group_id = group_json["id"]
  if group_id.nil?
    p "找不到group"
  end

  milestones_string = `curl --header "PRIVATE-TOKEN: #{private_token}" "#{prefix_url}/groups/#{group_id}/milestones?per_page=1000"`
  milestones_json = JSON.parse(milestones_string)
  mile_stone_json = milestones_json.filter { |t| t["title"] == mile_stone_title }&.first
  mile_stone_id = mile_stone_json["id"]
  if mile_stone_id.nil?
    p "找不到mile_stone"
  end

  issues_string = `curl --header "PRIVATE-TOKEN: #{private_token}" "#{prefix_url}/groups/#{group_id}/milestones/#{mile_stone_id}/issues?per_page=10000"`
  issues_json = JSON.parse(issues_string)
  issues_json
end

.start_project(prefix_url, private_token, project_name, mile_stone_title) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/get_issues.rb', line 29

def self.start_project(prefix_url, private_token, project_name, mile_stone_title)
  projects_string = `curl --header "PRIVATE-TOKEN: #{private_token}" "#{prefix_url}/projects?sort=asc&&order_by=name&&simple=true&&per_page=1000"`
  projects_json = JSON.parse(projects_string)
  project_json = projects_json.filter { |t| t["name"] == project_name }&.first || {}
  project_id = project_json["id"]
  if project_id.nil?
    p "找不到project"
  end
  milestones_string = `curl --header "PRIVATE-TOKEN: #{private_token}" "#{prefix_url}/projects/#{project_id}/milestones?per_page=1000"`
  milestones_json = JSON.parse(milestones_string)
  mile_stone_json = milestones_json.filter { |t| t["title"] == mile_stone_title }&.first || {}
  mile_stone_id = mile_stone_json["id"]
  if mile_stone_id.nil?
    p "找不到mile_stone"
  end
  issues_string = `curl --header "PRIVATE-TOKEN: #{private_token}" "#{prefix_url}/projects/#{project_id}/milestones/#{mile_stone_id}/issues?per_page=10000"`
  issues_json = JSON.parse(issues_string)
  issues_json
end

.to_xlsx(issues_json, mile_stone_title) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/get_issues.rb', line 49

def self.to_xlsx(issues_json,mile_stone_title)
  data = []
  issues_json.each do |issue|
    assignes_names = issue["assignees"]&.map { |t| t["name"]&.split(" ")&.reverse&.join("") }&.join(",")
    milestone = issue["milestone"]["title"] rescue ""
    data << ["##{issue["iid"]}",issue["title"], assignes_names, issue["labels"]&.join(","), milestone]
  end
  headers = %w(编号 标题 负责人 标签 归属端)
  options = { headers: headers, data: data, header_style: init_header_style, row_style: init_row_style }
  file_data = SpreadsheetArchitect.to_xlsx(options)
  file = File.open("#{mile_stone_title}.xlsx".to_s, "wb+") do |f|
    f.write file_data
  end
end

.to_xlsx_group(prefix_url, private_token, group_name, mile_stone_title) ⇒ Object



63
64
65
66
# File 'lib/get_issues.rb', line 63

def self.to_xlsx_group(prefix_url,private_token,group_name,mile_stone_title)
  issues_json = start_group(prefix_url,private_token,group_name,mile_stone_title)
  to_xlsx(issues_json,mile_stone_title)
end

.to_xlsx_project(prefix_url, private_token, project_name, mile_stone_title) ⇒ Object



67
68
69
70
# File 'lib/get_issues.rb', line 67

def self.to_xlsx_project(prefix_url, private_token, project_name, mile_stone_title)
  issues_json = start_project(prefix_url, private_token, project_name, mile_stone_title)
  to_xlsx(issues_json,mile_stone_title)
end