Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.3.10 #106

Open
wants to merge 18 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ name: Ruby
on:
push:
branches: [ "master" ]
paths-ignore:
- 'README.md'
pull_request:
branches: [ "master", "develop" ]
paths-ignore:
- 'README.md'

permissions:
contents: read
Expand Down
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,77 @@ If you need to uninstall RVM, you can do so with the following command:
```shell
rvm implode
```

# Console

The bin/console script allows you to interact with the application in an interactive Ruby (IRB) session.
This can be useful for debugging, running commands, and interacting with the application's models and database.

## Available Commands

- find_organization(name)
- Description: Finds an organization by its name.
- Parameters:
- name: The name of the organization to find.

- create_organization(name, attributes = {})
- Description: Creates a new organization with the given attributes.
- Parameters:
- name: The name of the organization to create.
- attributes: A hash of attributes for the organization.
- contact_email: The contact email of the organization (string).
- contact_name: The contact name of the organization (string).
- url: The URL of the organization (string).

- edit_organization(name, attributes = {})
- Description: Edits an existing organization with the given attributes.
- Parameters:
- name: The name of the organization to edit.
- attributes: A hash of attributes to update for the organization.
- contact_email: The contact email of the organization (string).
- contact_name: The contact name of the organization (string).
- url: The URL of the organization (string).

- find_github_user(login)
- Description: Finds a GitHub user by their login.
- Parameters:
- login: The GitHub login of the user to find.

- add_user_in_organization(login, organization_name)
- Description: Adds a GitHub user to an organization.
- Parameters:
- login: The GitHub login of the user to add.
- organization_name: The name of the organization to add the user to.

- remove_user_from_organization(login)
- Description: Removes a GitHub user from their organization.
- Parameters:
- login: The GitHub login of the user to remove.

- add_github_user_slack_user(github_login, slack_user)
- Description: Links a GitHub user to a Slack user.
- Parameters:
- github_login: The GitHub login of the user to link.
- slack_user: The Slack username to link to the GitHub user.

Examples
- Find an organization by name:
- find_organization('NetDEF')
-
- Create a new organization:
- create_organization('NetDEF', contact_name: 'Rodrigo Nardi')

- Edit an existing organization:
- edit_organization('NetDEF', contact_name: 'Martin Winter')

- Find a GitHub user by login:
- find_github_user('rodrigonardi')

- Add a user to an organization:
- add_user_in_organization('rodrigonardi', 'NetDEF')

- Remove a user from an organization:
- remove_user_from_organization('rodrigonardi')

- Link a GitHub user to a Slack user:
- add_github_user_slack_user('rodrigonardi', 'slack_user')
2 changes: 0 additions & 2 deletions config/delayed_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class << self
Delayed::Worker.max_attempts = 5
Delayed::Worker.max_run_time = 5.minutes

Delayed::Job.delete_all unless ENV.fetch('RAILS_ENV', 'test') == 'test'

# Load the database configuration

config = YAML.load_file('config/database.yml')[ENV.fetch('RACK_ENV', 'development')]
Expand Down
65 changes: 65 additions & 0 deletions lib/github/build/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
# action.rb
# Part of NetDEF CI System
#
# This class handles the build action for a given CheckSuite.
# It creates summaries, jobs, and timeout workers for the CheckSuite.
#
# Methods:
# - initialize(check_suite, github, jobs, logger_level: Logger::INFO): Initializes the Action class with the
# given parameters.
# - create_summary(rerun: false): Creates a summary for the CheckSuite, including jobs and timeout workers.
#
# Example usage:
# Github::Build::Action.new(check_suite, github, jobs).create_summary
#
# Copyright (c) 2023 by
# Network Device Education Foundation, Inc. ("NetDEF")
#
Expand All @@ -11,6 +22,13 @@
module Github
module Build
class Action
##
# Initializes the Action class with the given parameters.
#
# @param [CheckSuite] check_suite The CheckSuite to handle.
# @param [Github] github The Github instance to use.
# @param [Array] jobs The jobs to create for the CheckSuite.
# @param [Integer] logger_level The logging level to use (default: Logger::INFO).
def initialize(check_suite, github, jobs, logger_level: Logger::INFO)
@check_suite = check_suite
@github = github
Expand All @@ -26,6 +44,10 @@ def initialize(check_suite, github, jobs, logger_level: Logger::INFO)
logger(Logger::WARN, ">>>> Building action to CheckSuite: #{@check_suite.inspect}")
end

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

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

logger(Logger::INFO, "@jobs - #{@jobs.inspect}")
create_jobs(rerun)
create_timeout_worker
end

private

##
# Creates jobs for the CheckSuite.
#
# @param [Boolean] rerun Indicates if the jobs should be rerun.
def create_jobs(rerun)
@jobs.each do |job|
ci_job = create_ci_job(job)
Expand All @@ -60,13 +87,32 @@ def create_jobs(rerun)
end
end

##
# Creates a timeout worker for the CheckSuite.
def create_timeout_worker
logger(Logger::INFO, "CiJobStatus::Update: TimeoutExecution for '#{@check_suite.id}'")

TimeoutExecution
.delay(run_at: 30.minute.from_now.utc, queue: 'timeout_execution')
.timeout(@check_suite.id)
end

##
# Starts the stage in progress if configured to do so.
#
# @param [CiJob] ci_job The CI job to start in progress.
def stage_with_start_in_progress(ci_job)
return unless !ci_job.stage.nil? and ci_job.stage.configuration.start_in_progress?

ci_job.in_progress(@github)
ci_job.stage.in_progress(@github, output: {})
end

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

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

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

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

##
# Creates a new stage for the given stage configuration.
#
# @param [StageConfiguration] stage_config The stage configuration.
# @return [Stage] The created stage.
def create_stage(stage_config)
name = stage_config.github_check_run_name

Expand All @@ -110,6 +165,11 @@ def create_stage(stage_config)
stage
end

##
# Generates the initial output for a CI job.
#
# @param [CiJob] ci_job The CI job.
# @return [Hash] The initial output.
def initial_output(ci_job)
output = { title: '', summary: '' }
url = "https://ci1.netdef.org/browse/#{ci_job.check_suite.bamboo_ci_ref}"
Expand All @@ -120,6 +180,11 @@ def initial_output(ci_job)
output
end

##
# Logs a message with the given severity.
#
# @param [Integer] severity The severity level.
# @param [String] message The message to log.
def logger(severity, message)
@loggers.each do |logger_object|
logger_object.add(severity, message)
Expand Down
Loading
Loading