Skip to content

Commit

Permalink
Fix delete type (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
winterjung authored Jul 5, 2020
1 parent 7243fdc commit fda92db
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
python3 main.py
env:
INPUT_TYPE: delete
INPUT_COMMENT_ID: "${{ steps.create.outputs.id }}"
INPUT_COMMENT_ID: "${{ steps.edit.outputs.id }}"
INPUT_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test delete
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
## Inputs

- `type`: `create`, `edit` or `delete`
- `body`: Comment body
- `token`: GitHub token
- `comment_id`: Comment id to edit body. Required with `edit` type.
- `body`: Comment body. Required with `create` and `edit` type.
- `comment_id`: Comment id to edit body. Required with `edit` and `delete` type.
- `issue_number`: Number of PR, issue to comment. Required with `create` type.

## Outputs
Expand Down
10 changes: 5 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ inputs:
type:
required: true
description: create|edit
body:
required: true
description: comment body
token:
required: true
description: github token
body:
required: false
description: comment body
comment_id:
required: false
description: required when edit comment
description: required when edit, delete comment
issue_number:
required: false
description: required when create comment
Expand All @@ -29,7 +29,7 @@ runs:
image: docker://winterjung/comment:v1
args:
- ${{ inputs.type }}
- ${{ inputs.body }}
- ${{ inputs.token }}
- ${{ inputs.body }}
- ${{ inputs.comment_id }}
- ${{ inputs.issue_number }}
13 changes: 7 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from http import HTTPStatus
from typing import Optional, Tuple

import requests
Expand Down Expand Up @@ -47,7 +48,7 @@ def create(token, repo, body, issue_number) -> Tuple[str, str]:
headers=headers,
json=data,
)
if resp.status_code != 201:
if resp.status_code != HTTPStatus.CREATED:
print_action_error(f'cannot create comment')
print_action_debug(f'status code: {resp.status_code}')
print_action_debug(f'response body: {resp.text}')
Expand All @@ -69,7 +70,7 @@ def edit(token, repo, body, comment_id) -> Tuple[str, str]:
headers=headers,
json=data,
)
if resp.status_code != 200:
if resp.status_code != HTTPStatus.OK:
print_action_error(f'cannot edit comment')
print_action_debug(f'status code: {resp.status_code}')
print_action_debug(f'response body: {resp.text}')
Expand All @@ -87,20 +88,20 @@ def delete(token, repo, comment_id) -> Tuple[str, str]:
f'{GITHUB_API_BASE_URL}/repos/{repo}/issues/comments/{comment_id}',
headers=headers,
)
if resp.status_code != 204:
if resp.status_code != HTTPStatus.NO_CONTENT:
print_action_error(f'cannot delete comment')
print_action_debug(f'status code: {resp.status_code}')
print_action_debug(f'response body: {resp.text}')
exit(1)

return '', ''
return '', ''


def main():
repo = os.environ['GITHUB_REPOSITORY']
action_type = get_action_input('type', required=True)
body = get_action_input('body', required=True)
token = get_action_input('token', required=True)
body = get_action_input('body')
comment_id = get_action_input('comment_id')
issue_number = get_action_input('issue_number')

Expand All @@ -110,7 +111,7 @@ def main():
elif action_type == 'edit':
_id, _body = edit(token, repo, body, comment_id)
elif action_type == 'delete':
_id, _body = edit(token, repo, comment_id)
_id, _body = delete(token, repo, comment_id)

set_action_output('id', _id)
set_action_output('body', _body)
Expand Down

0 comments on commit fda92db

Please sign in to comment.