diff --git a/.env b/.env index 7637cb7..ebf7f39 100644 --- a/.env +++ b/.env @@ -1,13 +1,13 @@ -RAILS_HOST_NAME=scibot.test +RAILS_HOST_NAME=localhost:3000 BASE_URL=https://${RAILS_HOST_NAME} -DATABASE_URL="postgres://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}?pool=30" +DATABASE_HOST=db DATABASE_NAME=scibot DATABASE_PASSWORD=testing123 DATABASE_USER=postgres -DATABASE_HOST=db -RAILS_ENV=development -RAILS_SECRET_TOKEN= -SLACK_CLIENT_ID= -SLACK_CLIENT_SECRET= -SLACK_OAUTH_SCOPE= -SLACK_SIGNING_SECRET= +DATABASE_URL="postgres://${DATABASE_USER}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}?pool=30" +RAILS_SECRET_TOKEN=CHANGEME +SLACK_CLIENT_ID=CHANGEME +SLACK_CLIENT_SECRET=CHANGEME +SLACK_SIGNING_SECRET=CHANGEME +SLACK_OAUTH_SCOPE=users:read,channels:read,groups:read,chat:write,commands,incoming-webhook +GITHUB_REPOSITORY=scientist-softserv/dev-ops \ No newline at end of file diff --git a/bot/actions.rb b/bot/actions.rb index 261ae50..25bf2b3 100644 --- a/bot/actions.rb +++ b/bot/actions.rb @@ -1,3 +1,4 @@ require_relative 'actions/default' require_relative 'actions/quiz' require_relative 'actions/modal' +require_relative 'actions/ticket' \ No newline at end of file diff --git a/bot/actions/ticket.rb b/bot/actions/ticket.rb new file mode 100644 index 0000000..3e5d683 --- /dev/null +++ b/bot/actions/ticket.rb @@ -0,0 +1,26 @@ +SlackRubyBotServer::Events.configure do |config| + config.on :action, 'block_actions' do |action| + payload = action[:payload] + action_id = payload["actions"][0]["action_id"] + channel_id = payload["channel"]["id"] + team_id = payload["team"]["id"] + user_id = payload["user"]["id"] + action.logger.info "Action #{action_id} has been processed in channel #{channel_id}" + team = Team.find_by(team_id: team_id) + slack_client = Slack::Web::Client.new(token: team.token) + + case action_id + when 'create_issue' + # Handle the create issue action for /ticket + issue_title = payload["state"]["values"]["ticket_title"]["value"] + issue_description = payload["state"]["values"]["ticket_description"]["value"] + + # scibot channel id for now + channel_id = 'C065NSAGFAM' + # Go to scibot channel and put the payload there. + slack_client.chat_postMessage(channel: channel_id, text: "Issue title: #{issue_title}\nIssue description: #{issue_description}") + end + + nil + end +end \ No newline at end of file diff --git a/bot/slash_commands.rb b/bot/slash_commands.rb index 222ed28..72b3319 100644 --- a/bot/slash_commands.rb +++ b/bot/slash_commands.rb @@ -2,3 +2,4 @@ require_relative 'slash_commands/ping' require_relative 'slash_commands/quiz' require_relative 'slash_commands/modal' +require_relative 'slash_commands/ticket' \ No newline at end of file diff --git a/bot/slash_commands/ticket.rb b/bot/slash_commands/ticket.rb new file mode 100644 index 0000000..c71eba6 --- /dev/null +++ b/bot/slash_commands/ticket.rb @@ -0,0 +1,76 @@ +def ticket_message(channel_id) + { + channel: channel_id, + "blocks": [ + { + "type": "section", + "text": { + "type": "plain_text", + "text": "Please enter the title of the issue:", + "emoji": true + } + }, + { + "type": "input", + "element": { + "type": "plain_text_input", + "action_id": "ticket_title" + }, + "label": { + "type": "plain_text", + "text": "Title", + "emoji": true + } + }, + { + "type": "section", + "text": { + "type": "plain_text", + "text": "Please enter the description of the issue:", + "emoji": true + } + }, + { + "type": "input", + "element": { + "type": "plain_text_input", + "multiline": true, + "action_id": "ticket_description" + }, + "label": { + "type": "plain_text", + "text": "Description", + "emoji": true + } + }, + { + "type": "actions", + "elements": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": "Create Issue", + "emoji": true + }, + "value": "create_issue", + "action_id": "create_issue" + } + ] + } + ] + } +end + +SlackRubyBotServer::Events.configure do |config| + config.on :command, '/ticket' do |command| + p command + team_id = command[:team_id] + channel_id = command[:channel_id] + command.logger.info "Someone started a ticket creation in channel #{channel_id}." + team = Team.find_by(team_id: team_id) + slack_client = Slack::Web::Client.new(token: team.token) + slack_client.chat_postMessage(ticket_message(channel_id)) + nil + end +end diff --git a/db/seed.rb b/db/seed.rb deleted file mode 100644 index 578c0b5..0000000 --- a/db/seed.rb +++ /dev/null @@ -1,27 +0,0 @@ -Group.find_or_create_by(name: 'devops') do |group| - group.description = "SoftServ DevOps Team" -end - -Group.find_or_create_by(name: 'gcsupport') do |group| - group.description = "Glass Canvas Support Team" -end - -Group.find_or_create_by(name: 'gcdev') do |group| - group.description = "Glass Canvas Dev Team" -end - -Member.find_or_create_by(handle: 'rob') do |member| - member.name = "Rob Kaufman" - member.group = Group.find_by(name: 'devops') - member.member_id = "U0E347KGF" -end - -Member.find_or_create_by(handle: 'crystal') do |member| - member.name = "Crystal Richardson" - member.group = Group.find_by(name: 'devops') -end - -Member.find_or_create_by(handle: 'stefan') do |member| - member.name = "Stefan" - member.group = Group.find_by(name: 'gcdev') -end diff --git a/db/seeds.rb b/db/seeds.rb index 578c0b5..5450474 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,27 +1,11 @@ -Group.find_or_create_by(name: 'devops') do |group| - group.description = "SoftServ DevOps Team" -end - -Group.find_or_create_by(name: 'gcsupport') do |group| - group.description = "Glass Canvas Support Team" -end - -Group.find_or_create_by(name: 'gcdev') do |group| - group.description = "Glass Canvas Dev Team" -end +# frozen_string_literal: true -Member.find_or_create_by(handle: 'rob') do |member| - member.name = "Rob Kaufman" - member.group = Group.find_by(name: 'devops') - member.member_id = "U0E347KGF" +Group.find_or_create_by(name: 'devops') do |group| + group.description = 'SoftServ DevOps Team' end -Member.find_or_create_by(handle: 'crystal') do |member| - member.name = "Crystal Richardson" +Member.find_or_create_by(member_id: 'U02QC5MTU8N') do |member| + member.handle = 'april' + member.name = 'April Rieger' member.group = Group.find_by(name: 'devops') end - -Member.find_or_create_by(handle: 'stefan') do |member| - member.name = "Stefan" - member.group = Group.find_by(name: 'gcdev') -end