diff --git a/action.yml b/action.yml index b77f2fb..d07a6d6 100644 --- a/action.yml +++ b/action.yml @@ -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" @@ -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 @@ -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 }}" diff --git a/main.rb b/main.rb index 6fb22d8..b755f6c 100644 --- a/main.rb +++ b/main.rb @@ -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