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

remove deprecated task feature #53

Merged
merged 4 commits into from
Aug 8, 2024
Merged
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
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].to_s }

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, "action failed! #{response.body}"
end