Skip to content

Commit 7231a8a

Browse files
Merge pull request #106 from FRRouting/master
Release 2.3.10
2 parents 9b27c76 + 6835daa commit 7231a8a

13 files changed

Lines changed: 355 additions & 59 deletions

File tree

.github/workflows/ruby.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ name: Ruby
1010
on:
1111
push:
1212
branches: [ "master" ]
13+
paths-ignore:
14+
- 'README.md'
1315
pull_request:
1416
branches: [ "master", "develop" ]
17+
paths-ignore:
18+
- 'README.md'
1519

1620
permissions:
1721
contents: read

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,77 @@ If you need to uninstall RVM, you can do so with the following command:
208208
```shell
209209
rvm implode
210210
```
211+
212+
# Console
213+
214+
The bin/console script allows you to interact with the application in an interactive Ruby (IRB) session.
215+
This can be useful for debugging, running commands, and interacting with the application's models and database.
216+
217+
## Available Commands
218+
219+
- find_organization(name)
220+
- Description: Finds an organization by its name.
221+
- Parameters:
222+
- name: The name of the organization to find.
223+
224+
- create_organization(name, attributes = {})
225+
- Description: Creates a new organization with the given attributes.
226+
- Parameters:
227+
- name: The name of the organization to create.
228+
- attributes: A hash of attributes for the organization.
229+
- contact_email: The contact email of the organization (string).
230+
- contact_name: The contact name of the organization (string).
231+
- url: The URL of the organization (string).
232+
233+
- edit_organization(name, attributes = {})
234+
- Description: Edits an existing organization with the given attributes.
235+
- Parameters:
236+
- name: The name of the organization to edit.
237+
- attributes: A hash of attributes to update for the organization.
238+
- contact_email: The contact email of the organization (string).
239+
- contact_name: The contact name of the organization (string).
240+
- url: The URL of the organization (string).
241+
242+
- find_github_user(login)
243+
- Description: Finds a GitHub user by their login.
244+
- Parameters:
245+
- login: The GitHub login of the user to find.
246+
247+
- add_user_in_organization(login, organization_name)
248+
- Description: Adds a GitHub user to an organization.
249+
- Parameters:
250+
- login: The GitHub login of the user to add.
251+
- organization_name: The name of the organization to add the user to.
252+
253+
- remove_user_from_organization(login)
254+
- Description: Removes a GitHub user from their organization.
255+
- Parameters:
256+
- login: The GitHub login of the user to remove.
257+
258+
- add_github_user_slack_user(github_login, slack_user)
259+
- Description: Links a GitHub user to a Slack user.
260+
- Parameters:
261+
- github_login: The GitHub login of the user to link.
262+
- slack_user: The Slack username to link to the GitHub user.
263+
264+
Examples
265+
- Find an organization by name:
266+
- find_organization('NetDEF')
267+
-
268+
- Create a new organization:
269+
- create_organization('NetDEF', contact_name: 'Rodrigo Nardi')
270+
271+
- Edit an existing organization:
272+
- edit_organization('NetDEF', contact_name: 'Martin Winter')
273+
274+
- Find a GitHub user by login:
275+
- find_github_user('rodrigonardi')
276+
277+
- Add a user to an organization:
278+
- add_user_in_organization('rodrigonardi', 'NetDEF')
279+
280+
- Remove a user from an organization:
281+
- remove_user_from_organization('rodrigonardi')
282+
283+
- Link a GitHub user to a Slack user:
284+
- add_github_user_slack_user('rodrigonardi', 'slack_user')

config/delayed_job.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class << self
3434
Delayed::Worker.max_attempts = 5
3535
Delayed::Worker.max_run_time = 5.minutes
3636

37-
Delayed::Job.delete_all unless ENV.fetch('RAILS_ENV', 'test') == 'test'
38-
3937
# Load the database configuration
4038

4139
config = YAML.load_file('config/database.yml')[ENV.fetch('RACK_ENV', 'development')]

lib/github/build/action.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
# action.rb
44
# Part of NetDEF CI System
55
#
6+
# This class handles the build action for a given CheckSuite.
7+
# It creates summaries, jobs, and timeout workers for the CheckSuite.
8+
#
9+
# Methods:
10+
# - initialize(check_suite, github, jobs, logger_level: Logger::INFO): Initializes the Action class with the
11+
# given parameters.
12+
# - create_summary(rerun: false): Creates a summary for the CheckSuite, including jobs and timeout workers.
13+
#
14+
# Example usage:
15+
# Github::Build::Action.new(check_suite, github, jobs).create_summary
16+
#
617
# Copyright (c) 2023 by
718
# Network Device Education Foundation, Inc. ("NetDEF")
819
#
@@ -11,6 +22,13 @@
1122
module Github
1223
module Build
1324
class Action
25+
##
26+
# Initializes the Action class with the given parameters.
27+
#
28+
# @param [CheckSuite] check_suite The CheckSuite to handle.
29+
# @param [Github] github The Github instance to use.
30+
# @param [Array] jobs The jobs to create for the CheckSuite.
31+
# @param [Integer] logger_level The logging level to use (default: Logger::INFO).
1432
def initialize(check_suite, github, jobs, logger_level: Logger::INFO)
1533
@check_suite = check_suite
1634
@github = github
@@ -26,6 +44,10 @@ def initialize(check_suite, github, jobs, logger_level: Logger::INFO)
2644
logger(Logger::WARN, ">>>> Building action to CheckSuite: #{@check_suite.inspect}")
2745
end
2846

47+
##
48+
# Creates a summary for the CheckSuite, including jobs and timeout workers.
49+
#
50+
# @param [Boolean] rerun Indicates if the jobs should be rerun (default: false).
2951
def create_summary(rerun: false)
3052
logger(Logger::INFO, "SUMMARY #{@stages.inspect}")
3153

@@ -37,10 +59,15 @@ def create_summary(rerun: false)
3759

3860
logger(Logger::INFO, "@jobs - #{@jobs.inspect}")
3961
create_jobs(rerun)
62+
create_timeout_worker
4063
end
4164

4265
private
4366

67+
##
68+
# Creates jobs for the CheckSuite.
69+
#
70+
# @param [Boolean] rerun Indicates if the jobs should be rerun.
4471
def create_jobs(rerun)
4572
@jobs.each do |job|
4673
ci_job = create_ci_job(job)
@@ -60,13 +87,32 @@ def create_jobs(rerun)
6087
end
6188
end
6289

90+
##
91+
# Creates a timeout worker for the CheckSuite.
92+
def create_timeout_worker
93+
logger(Logger::INFO, "CiJobStatus::Update: TimeoutExecution for '#{@check_suite.id}'")
94+
95+
TimeoutExecution
96+
.delay(run_at: 30.minute.from_now.utc, queue: 'timeout_execution')
97+
.timeout(@check_suite.id)
98+
end
99+
100+
##
101+
# Starts the stage in progress if configured to do so.
102+
#
103+
# @param [CiJob] ci_job The CI job to start in progress.
63104
def stage_with_start_in_progress(ci_job)
64105
return unless !ci_job.stage.nil? and ci_job.stage.configuration.start_in_progress?
65106

66107
ci_job.in_progress(@github)
67108
ci_job.stage.in_progress(@github, output: {})
68109
end
69110

111+
##
112+
# Creates a CI job for the given job parameters.
113+
#
114+
# @param [Hash] job The job parameters.
115+
# @return [CiJob, nil] The created CI job or nil if the stage configuration is not found.
70116
def create_ci_job(job)
71117
stage_config = StageConfiguration.find_by(bamboo_stage_name: job[:stage])
72118

@@ -79,6 +125,10 @@ def create_ci_job(job)
79125
CiJob.create(check_suite: @check_suite, name: job[:name], job_ref: job[:job_ref], stage: stage)
80126
end
81127

128+
##
129+
# Creates a check run stage for the given stage configuration.
130+
#
131+
# @param [StageConfiguration] stage_config The stage configuration.
82132
def create_check_run_stage(stage_config)
83133
stage = Stage.find_by(name: stage_config.github_check_run_name, check_suite_id: @check_suite.id)
84134

@@ -92,6 +142,11 @@ def create_check_run_stage(stage_config)
92142
stage.enqueue(@github, output: initial_output(stage))
93143
end
94144

145+
##
146+
# Creates a new stage for the given stage configuration.
147+
#
148+
# @param [StageConfiguration] stage_config The stage configuration.
149+
# @return [Stage] The created stage.
95150
def create_stage(stage_config)
96151
name = stage_config.github_check_run_name
97152

@@ -110,6 +165,11 @@ def create_stage(stage_config)
110165
stage
111166
end
112167

168+
##
169+
# Generates the initial output for a CI job.
170+
#
171+
# @param [CiJob] ci_job The CI job.
172+
# @return [Hash] The initial output.
113173
def initial_output(ci_job)
114174
output = { title: '', summary: '' }
115175
url = "https://ci1.netdef.org/browse/#{ci_job.check_suite.bamboo_ci_ref}"
@@ -120,6 +180,11 @@ def initial_output(ci_job)
120180
output
121181
end
122182

183+
##
184+
# Logs a message with the given severity.
185+
#
186+
# @param [Integer] severity The severity level.
187+
# @param [String] message The message to log.
123188
def logger(severity, message)
124189
@loggers.each do |logger_object|
125190
logger_object.add(severity, message)

0 commit comments

Comments
 (0)