Skip to content

Commit

Permalink
remove task feature
Browse files Browse the repository at this point in the history
  • Loading branch information
okuzawats committed Aug 8, 2024
1 parent 49e7182 commit f301611
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 62 deletions.
20 changes: 0 additions & 20 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,9 @@ inputs:
roomId:
required: true
description: "Chatroom ID"
# deprecated inputs. this inputs parameter will be removed in the future version.
messageType:
description: "Message type to send. default is message."
type: "choice"
default: "message"
required: false
options:
- "message"
- "task"
message:
required: true
description: "Message to send"
# deprecated inputs. this inputs parameter will be removed in the future version.
userIdsToAssignTask:
required: false
description: "User Id to be assigned to the task. Or you can specify multiple users, separated by commas. example 1,3,5"

runs:
using: "composite"
Expand All @@ -38,11 +25,6 @@ runs:
fetch-depth: 0
- name: "set up ruby"
uses: "ruby/setup-ruby@v1"
- name: "deprecate messageType"
if: ${{ !github.event.inputs.messageType }}
run: |
echo "::warning::messageType is now deprecated. If you use only message, just remove the parameter. Or if you use task, please use okuzawats/chatwork-task-action instead. In this case, remove userIdsToAssignTask parameter also."
shell: "sh"
- name: "run action"
run: |
ruby $GITHUB_ACTION_PATH/main.rb
Expand All @@ -51,5 +33,3 @@ runs:
API_TOKEN: "${{ inputs.apiToken }}"
ROOM_ID: "${{ inputs.roomId }}"
MESSAGE: "${{ inputs.message }}"
MESSAGE_TYPE: "${{ inputs.messageType }}"
USER_IDS_TO_ASSIGN_TASK: "${{ inputs.userIdsToAssignTask }}"
52 changes: 10 additions & 42 deletions main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,19 @@
token: ENV['API_TOKEN'],
room_id: ENV['ROOM_ID'],
message: ENV['MESSAGE'].delete_prefix('"').delete_suffix('"'),
message_type: ENV['MESSAGE_TYPE'],
user_ids_to_assign_task: ENV['USER_IDS_TO_ASSIGN_TASK']
}

# message type must be message or task.
type = params[:message_type]
valid_types = ["message", "task"]
unless valid_types.include?(type)
raise StandardError.new("type should be message or task.")
end

if params[:message].empty?
raise StandardError.new("empty message is not allowed.")
end

if type == "message"
uri = URI.parse("https://api.chatwork.com/v2/rooms/#{params[:room_id]}/messages")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

body = "body=#{params[:message]}"
headers = { "X-ChatWorkToken" => "#{params[:token]}" }

response = http.post(uri.path, body, headers)

if response.code == '200'
puts response.body
else
raise StandardError.new("action failed! #{response.body}")
end
end

if type == "task"
uri = URI.parse("https://api.chatwork.com/v2/rooms/#{params[:room_id]}/tasks")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
uri = URI.parse("https://api.chatwork.com/v2/rooms/#{params[:room_id]}/messages")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

body = "body=#{params[:message]}&to_ids=#{params[:user_ids_to_assign_task]}"
headers = { "X-ChatWorkToken" => "#{params[:token]}" }
body = "body=#{params[:message]}"
headers = { "X-ChatWorkToken" => "#{params[:token]}" }

response = http.post(uri.path, body, headers)
response = http.post(uri.path, body, headers)

if response.code == '200'
puts response.body
else
raise StandardError.new("action failed! #{response.body}")
end
if response.code == '200'
puts response.body
else
raise StandardError.new("action failed! #{response.body}")
end

0 comments on commit f301611

Please sign in to comment.