Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 1c0b681

Browse files
remove deprecated task feature (#53)
* remove task feature * use single quote instead of double quote Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * provide exception class nad message as arguments to raise Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * use to_s --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 49e7182 commit 1c0b681

File tree

2 files changed

+10
-62
lines changed

2 files changed

+10
-62
lines changed

action.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,9 @@ inputs:
1212
roomId:
1313
required: true
1414
description: "Chatroom ID"
15-
# deprecated inputs. this inputs parameter will be removed in the future version.
16-
messageType:
17-
description: "Message type to send. default is message."
18-
type: "choice"
19-
default: "message"
20-
required: false
21-
options:
22-
- "message"
23-
- "task"
2415
message:
2516
required: true
2617
description: "Message to send"
27-
# deprecated inputs. this inputs parameter will be removed in the future version.
28-
userIdsToAssignTask:
29-
required: false
30-
description: "User Id to be assigned to the task. Or you can specify multiple users, separated by commas. example 1,3,5"
3118

3219
runs:
3320
using: "composite"
@@ -38,11 +25,6 @@ runs:
3825
fetch-depth: 0
3926
- name: "set up ruby"
4027
uses: "ruby/setup-ruby@v1"
41-
- name: "deprecate messageType"
42-
if: ${{ !github.event.inputs.messageType }}
43-
run: |
44-
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."
45-
shell: "sh"
4628
- name: "run action"
4729
run: |
4830
ruby $GITHUB_ACTION_PATH/main.rb
@@ -51,5 +33,3 @@ runs:
5133
API_TOKEN: "${{ inputs.apiToken }}"
5234
ROOM_ID: "${{ inputs.roomId }}"
5335
MESSAGE: "${{ inputs.message }}"
54-
MESSAGE_TYPE: "${{ inputs.messageType }}"
55-
USER_IDS_TO_ASSIGN_TASK: "${{ inputs.userIdsToAssignTask }}"

main.rb

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,19 @@
44
token: ENV['API_TOKEN'],
55
room_id: ENV['ROOM_ID'],
66
message: ENV['MESSAGE'].delete_prefix('"').delete_suffix('"'),
7-
message_type: ENV['MESSAGE_TYPE'],
8-
user_ids_to_assign_task: ENV['USER_IDS_TO_ASSIGN_TASK']
97
}
108

11-
# message type must be message or task.
12-
type = params[:message_type]
13-
valid_types = ["message", "task"]
14-
unless valid_types.include?(type)
15-
raise StandardError.new("type should be message or task.")
16-
end
17-
18-
if params[:message].empty?
19-
raise StandardError.new("empty message is not allowed.")
20-
end
21-
22-
if type == "message"
23-
uri = URI.parse("https://api.chatwork.com/v2/rooms/#{params[:room_id]}/messages")
24-
http = Net::HTTP.new(uri.host, uri.port)
25-
http.use_ssl = true
26-
27-
body = "body=#{params[:message]}"
28-
headers = { "X-ChatWorkToken" => "#{params[:token]}" }
29-
30-
response = http.post(uri.path, body, headers)
31-
32-
if response.code == '200'
33-
puts response.body
34-
else
35-
raise StandardError.new("action failed! #{response.body}")
36-
end
37-
end
38-
39-
if type == "task"
40-
uri = URI.parse("https://api.chatwork.com/v2/rooms/#{params[:room_id]}/tasks")
41-
http = Net::HTTP.new(uri.host, uri.port)
42-
http.use_ssl = true
9+
uri = URI.parse("https://api.chatwork.com/v2/rooms/#{params[:room_id]}/messages")
10+
http = Net::HTTP.new(uri.host, uri.port)
11+
http.use_ssl = true
4312

44-
body = "body=#{params[:message]}&to_ids=#{params[:user_ids_to_assign_task]}"
45-
headers = { "X-ChatWorkToken" => "#{params[:token]}" }
13+
body = "body=#{params[:message]}"
14+
headers = { 'X-ChatWorkToken' => params[:token].to_s }
4615

47-
response = http.post(uri.path, body, headers)
16+
response = http.post(uri.path, body, headers)
4817

49-
if response.code == '200'
50-
puts response.body
51-
else
52-
raise StandardError.new("action failed! #{response.body}")
53-
end
18+
if response.code == '200'
19+
puts response.body
20+
else
21+
raise StandardError, "action failed! #{response.body}"
5422
end

0 commit comments

Comments
 (0)