Skip to content

Commit 7d7210c

Browse files
Merge pull request #59 from FRRouting/master
Release 2.3.0
2 parents 5d2cf6b + 268971d commit 7d7210c

16 files changed

+367
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-License-Identifier: BSD-2-Clause
2+
#
3+
# 20240326112530_create_github_user_info.rb
4+
# Part of NetDEF CI System
5+
#
6+
# Copyright (c) 2024 by
7+
# Network Device Education Foundation, Inc. ("NetDEF")
8+
#
9+
# frozen_string_literal: true
10+
11+
class CreateGithubUserInfo < ActiveRecord::Migration[6.0]
12+
def change
13+
create_table :github_users do |t|
14+
t.string :github_login
15+
t.string :github_username
16+
t.string :github_email
17+
t.integer :github_id
18+
t.string :github_organization
19+
t.string :github_type
20+
t.string :organization_name
21+
t.string :organization_url
22+
23+
t.timestamps
24+
end
25+
end
26+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-License-Identifier: BSD-2-Clause
2+
#
3+
# 20240326121605_add_github_user_relations.rb
4+
# Part of NetDEF CI System
5+
#
6+
# Copyright (c) 2024 by
7+
# Network Device Education Foundation, Inc. ("NetDEF")
8+
#
9+
# frozen_string_literal: true
10+
11+
class AddGithubUserRelations < ActiveRecord::Migration[6.0]
12+
def change
13+
add_reference :pull_requests, :github_user, foreign_key: true
14+
add_reference :check_suites, :github_user, foreign_key: true
15+
add_reference :audit_retries, :github_user, foreign_key: true
16+
end
17+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: BSD-2-Clause
2+
#
3+
# 20240327112035_add_github_users_github_id_index.rb
4+
# Part of NetDEF CI System
5+
#
6+
# Copyright (c) 2024 by
7+
# Network Device Education Foundation, Inc. ("NetDEF")
8+
#
9+
# frozen_string_literal: true
10+
11+
class AddGithubUsersGithubIdIndex < ActiveRecord::Migration[6.0]
12+
def change
13+
add_index :github_users, :github_id, name: 'index_github_users_on_github_id', unique: true
14+
end
15+
end

db/schema.rb

+24-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2024_03_12_134402) do
13+
ActiveRecord::Schema[7.0].define(version: 2024_03_27_112035) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

@@ -22,7 +22,9 @@
2222
t.datetime "created_at", null: false
2323
t.datetime "updated_at", null: false
2424
t.bigint "check_suite_id"
25+
t.bigint "github_user_id"
2526
t.index ["check_suite_id"], name: "index_audit_retries_on_check_suite_id"
27+
t.index ["github_user_id"], name: "index_audit_retries_on_github_user_id"
2628
end
2729

2830
create_table "audit_retries_ci_jobs", id: false, force: :cascade do |t|
@@ -55,6 +57,8 @@
5557
t.boolean "re_run", default: false
5658
t.integer "retry", default: 0
5759
t.boolean "sync", default: false
60+
t.bigint "github_user_id"
61+
t.index ["github_user_id"], name: "index_check_suites_on_github_user_id"
5862
t.index ["pull_request_id"], name: "index_check_suites_on_pull_request_id"
5963
end
6064

@@ -73,6 +77,20 @@
7377
t.index ["stage_id"], name: "index_ci_jobs_on_stage_id"
7478
end
7579

80+
create_table "github_users", force: :cascade do |t|
81+
t.string "github_login"
82+
t.string "github_username"
83+
t.string "github_email"
84+
t.integer "github_id"
85+
t.string "github_organization"
86+
t.string "github_type"
87+
t.string "organization_name"
88+
t.string "organization_url"
89+
t.datetime "created_at", null: false
90+
t.datetime "updated_at", null: false
91+
t.index ["github_id"], name: "index_github_users_on_github_id", unique: true
92+
end
93+
7694
create_table "plans", force: :cascade do |t|
7795
t.string "bamboo_ci_plan_name", null: false
7896
t.string "github_repo_name", default: "0", null: false
@@ -101,6 +119,8 @@
101119
t.string "plan"
102120
t.datetime "created_at", null: false
103121
t.datetime "updated_at", null: false
122+
t.bigint "github_user_id"
123+
t.index ["github_user_id"], name: "index_pull_requests_on_github_user_id"
104124
end
105125

106126
create_table "stage_configurations", force: :cascade do |t|
@@ -138,11 +158,14 @@
138158
end
139159

140160
add_foreign_key "audit_retries", "check_suites"
161+
add_foreign_key "audit_retries", "github_users"
162+
add_foreign_key "check_suites", "github_users"
141163
add_foreign_key "check_suites", "pull_requests"
142164
add_foreign_key "ci_jobs", "check_suites"
143165
add_foreign_key "ci_jobs", "stages"
144166
add_foreign_key "plans", "check_suites"
145167
add_foreign_key "pull_request_subscriptions", "pull_requests"
168+
add_foreign_key "pull_requests", "github_users"
146169
add_foreign_key "stages", "check_suites"
147170
add_foreign_key "stages", "stage_configurations"
148171
add_foreign_key "topotest_failures", "ci_jobs"

lib/github/build_plan.rb

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
require_relative '../bamboo_ci/plan_run'
1717
require_relative 'check'
1818
require_relative 'build/action'
19+
require_relative 'user_info'
1920

2021
module Github
2122
class BuildPlan
@@ -91,9 +92,13 @@ def create_pull_request
9192
repository: @payload.dig('repository', 'full_name'),
9293
plan: fetch_plan
9394
)
95+
96+
Github::UserInfo.new(@payload.dig('pull_request', 'user', 'id'), pull_request: @pull_request)
9497
end
9598

9699
def start_new_execution
100+
Github::UserInfo.new(@payload.dig('pull_request', 'user', 'id'), check_suite: @check_suite)
101+
97102
@bamboo_plan_run = BambooCi::PlanRun.new(@check_suite, logger_level: @logger.level)
98103
@bamboo_plan_run.ci_variables = ci_vars
99104
@bamboo_plan_run.start_plan

lib/github/re_run/base.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
require_relative '../check'
1717
require_relative '../build/action'
1818
require_relative '../build/unavailable_jobs'
19+
require_relative '../user_info'
1920

2021
module Github
2122
module ReRun
@@ -81,11 +82,14 @@ def start_new_execution(check_suite)
8182
bamboo_plan_run.ci_variables = ci_vars
8283
bamboo_plan_run.start_plan
8384

84-
AuditRetry.create(check_suite: check_suite,
85-
github_username: @payload.dig('sender', 'login'),
86-
github_id: @payload.dig('sender', 'id'),
87-
github_type: @payload.dig('sender', 'type'),
88-
retry_type: 'full')
85+
audit_retry =
86+
AuditRetry.create(check_suite: check_suite,
87+
github_username: @payload.dig('sender', 'login'),
88+
github_id: @payload.dig('sender', 'id'),
89+
github_type: @payload.dig('sender', 'type'),
90+
retry_type: 'full')
91+
92+
Github::UserInfo.new(@payload.dig('sender', 'id'), check_suite: check_suite, audit_retry: audit_retry)
8993

9094
bamboo_plan_run
9195
end

lib/github/retry.rb

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def create_ci_jobs(check_suite)
6868
github_type: @payload.dig('sender', 'type'),
6969
retry_type: 'partial')
7070

71+
Github::UserInfo.new(@payload.dig('sender', 'id'), check_suite: check_suite, audit_retry: audit_retry)
72+
7173
build_retry = Github::Build::Retry.new(check_suite, github_check, audit_retry)
7274

7375
build_retry.enqueued_stages

lib/github/user_info.rb

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# SPDX-License-Identifier: BSD-2-Clause
2+
#
3+
# user_info.rb
4+
# Part of NetDEF CI System
5+
#
6+
# Copyright (c) 2024 by
7+
# Network Device Education Foundation, Inc. ("NetDEF")
8+
#
9+
# frozen_string_literal: true
10+
11+
module Github
12+
class UserInfo
13+
def initialize(github_id, pull_request: nil, check_suite: nil, audit_retry: nil)
14+
@github_id = github_id
15+
@github = Github::Check.new nil
16+
@info = @github.fetch_username(github_id)
17+
18+
@pull_request = pull_request
19+
@check_suite = check_suite
20+
@audit_retry = audit_retry
21+
22+
@logger = GithubLogger.instance.create('github_user_info.log', Logger::INFO)
23+
24+
@logger.info("Fetching user info for github_id: #{@github_id}")
25+
@logger.info(@info.inspect)
26+
27+
fetch
28+
end
29+
30+
private
31+
32+
def fetch
33+
@user = GithubUser.find_by(github_id: @github_id)
34+
35+
@logger.info("User: #{@user.inspect}")
36+
37+
create_user_info if @user.nil?
38+
39+
update_user_info
40+
41+
add_pull_request unless @pull_request.nil?
42+
add_check_suite unless @check_suite.nil?
43+
add_retry unless @audit_retry.nil?
44+
end
45+
46+
def add_pull_request
47+
@user.pull_requests << @pull_request
48+
@user.save
49+
end
50+
51+
def add_check_suite
52+
@user.check_suites << @check_suite
53+
@user.save
54+
end
55+
56+
def add_retry
57+
@user.audit_retries << @audit_retry
58+
@user.save
59+
end
60+
61+
def update_user_info
62+
@user.update(
63+
github_login: @info[:login],
64+
github_username: @info[:name],
65+
github_email: @info[:email],
66+
github_type: @info[:type],
67+
organization_url: @info[:organizations_url],
68+
github_organization: @info[:company]
69+
)
70+
end
71+
72+
def create_user_info
73+
@user =
74+
GithubUser.create(
75+
github_id: @github_id,
76+
github_login: @info[:login],
77+
github_username: @info[:name],
78+
github_email: @info[:email],
79+
github_type: @info[:type],
80+
organization_url: @info[:organizations_url],
81+
github_organization: @info[:company]
82+
)
83+
end
84+
end
85+
end

lib/github_ci_app.rb

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
require_relative 'github/retry'
2727
require_relative 'github/update_status'
2828
require_relative 'github/plan_execution/finished'
29+
require_relative 'github/user_info'
2930

3031
# Helpers libs
3132
require_relative 'helpers/configuration'

lib/models/github_user.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-License-Identifier: BSD-2-Clause
2+
#
3+
# github_user_info.rb
4+
# Part of NetDEF CI System
5+
#
6+
# Copyright (c) 2024 by
7+
# Network Device Education Foundation, Inc. ("NetDEF")
8+
#
9+
# frozen_string_literal: true
10+
11+
require 'otr-activerecord'
12+
13+
class GithubUser < ActiveRecord::Base
14+
has_many :pull_requests, dependent: :nullify
15+
has_many :check_suites, dependent: :nullify
16+
has_many :audit_retries, dependent: :nullify
17+
end

reports/re_run_report.rb

+16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# frozen_string_literal: true
1010

1111
require 'json'
12+
require 'csv'
1213
require_relative '../database_loader'
1314

1415
module Reports
@@ -57,6 +58,8 @@ def save_rerun_info(result, output, filename)
5758
case output
5859
when 'json'
5960
File.write(filename, result.to_json)
61+
when 'csv'
62+
create_csv(filename)
6063
when 'file'
6164
File.open(filename, 'a') do |f|
6265
raw_output(result, file_descriptor: f)
@@ -66,6 +69,19 @@ def save_rerun_info(result, output, filename)
6669
end
6770
end
6871

72+
def create_csv(filename)
73+
CSV.open(filename, 'wb') do |csv_input|
74+
csv_input << %w[PullRequest CheckSuiteId BambooJob GithubUsername RequestedAt Type TestsOrBuilds]
75+
@result.each_pair do |pull_requst, info|
76+
info[:check_suites].each do |cs|
77+
csv_input << [pull_requst,
78+
cs[:check_suite_id], cs[:bamboo_job], cs[:requested_at],
79+
cs[:github_username], cs[:type], cs[:tests_or_builds].join(',')]
80+
end
81+
end
82+
end
83+
end
84+
6985
def raw_output(result, file_descriptor: nil)
7086
result.each_pair do |pull_request, info|
7187
print("\nPull Request: ##{pull_request} - Reruns: #{info[:total]}", file_descriptor)

0 commit comments

Comments
 (0)