11#!/usr/bin/env ruby
22# SPDX-License-Identifier: BSD-2-Clause
33#
4- # organization_console.rb
4+ # console
55# Part of NetDEF CI System
66#
77# Copyright (c) 2023 by
1010# frozen_string_literal: true
1111
1212require 'irb'
13+
14+ ENV [ 'RAILS_ENV' ] = ARGV . shift || 'production'
15+
16+ puts "Starting console: #{ ENV . fetch ( 'RAILS_ENV' , nil ) } "
17+
1318require_relative '../config/setup'
19+ require_relative '../config/delayed_job'
1420
15- # Defina métodos para buscar e criar empresas
1621def find_organization ( name )
1722 organization = Organization . find_by ( name : name )
1823 if organization
@@ -97,7 +102,25 @@ def remove_user_from_organization(github_login)
97102 end
98103end
99104
100- def help
105+ def add_github_user_slack_user ( github_login , slack_user )
106+ user = GithubUser . find_by ( github_login : github_login )
107+
108+ if user . nil?
109+ puts 'Github user not found'
110+ return
111+ end
112+
113+ user . update ( slack_username : slack_user )
114+ SlackUsername2Id . fetch_id ( github_login , slack_user )
115+
116+ if user . persisted?
117+ puts "Slack user linked to github user: #{ user . inspect } "
118+ else
119+ puts "Failed to link slack user to github user: #{ user . errors . full_messages . join ( ', ' ) } "
120+ end
121+ end
122+
123+ def help?
101124 puts <<~HELP
102125 Available commands:
103126 - find_organization(name)
@@ -106,6 +129,7 @@ def help
106129 - find_github_user(login)
107130 - add_user_in_organization(login, organization_name)
108131 - remove_user_from_organization(login)
132+ - add_github_user_slack_user(github_login, slack_user)
109133
110134 create_organization / edit_organization attributes:
111135 - contact_email: string
@@ -122,5 +146,4 @@ def help
122146 HELP
123147end
124148
125- # Inicie o console IRB
126149IRB . start
0 commit comments