WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 8a271ce

Browse files
Add development environment (#20)
* Add development environment * Add pull request template
1 parent 6ec1fa4 commit 8a271ce

File tree

9 files changed

+97
-4
lines changed

9 files changed

+97
-4
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. -->
2+
3+
Fixes # (issue)

.github/workflows/test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: teamwork
2+
3+
on:
4+
pull_request:
5+
types: [opened, closed]
6+
pull_request_review:
7+
types: [submitted, dismissed]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
name: Ensure this project runs
13+
steps:
14+
- uses: actions/checkout@v1
15+
- uses: ./
16+
with:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
TEAMWORK_URI: "localhost"
19+
TEAMWORK_API_TOKEN: "test_api_token"

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
Simulate a new pull request
1313

1414
```
15-
act pull_request -e events/pull_request_opened.json
15+
act pull_request -e tests/events/pull_request_opened.json
1616
```
1717

1818
Simulate a pull request has been approved
1919

2020
```
21-
act pull_request -e events/pull_request_approved.json
21+
act pull_request_review -e tests/events/pull_request_approved.json
2222
```
2323

2424
Simulate a pull request has been merged
2525

2626
```
27-
act pull_request -e events/pull_request_merged.json
27+
act pull_request -e tests/events/pull_request_merged.json
2828
```

src/main.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ main() {
1818
export TEAMWORK_URI="$2"
1919
export TEAMWORK_API_TOKEN="$3"
2020

21+
env::set_environment
22+
2123
# Check if there is a task link in the PR
2224
local -r pr_body=$(github::get_pr_body)
2325
local -r task_id=$(teamwork::get_task_id_from_body "$pr_body" )

src/misc.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ log::message() {
88
echo "--------------"
99
echo "$@"
1010
}
11+
12+
env::set_environment() {
13+
if [ "$TEAMWORK_URI" == "localhost" ] && [ "$TEAMWORK_API_TOKEN" == "test_api_token" ]; then
14+
export ENV="test"
15+
else
16+
export ENV="prod"
17+
fi
18+
}

src/teamwork.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ teamwork::get_task_id_from_body() {
1313
teamwork::add_comment() {
1414
local -r body=$1
1515

16+
if [ "$ENV" == "test" ]; then
17+
log::message "Test - Simulate request. Task ID: $TEAMWORK_TASK_ID - Comment: ${body//\"/}"
18+
return
19+
fi
20+
1621
response=$(curl -X "POST" "$TEAMWORK_URI/projects/api/v1/tasks/$TEAMWORK_TASK_ID/comments.json" \
1722
-u "$TEAMWORK_API_TOKEN"':' \
1823
-H 'Content-Type: application/json; charset=utf-8' \
1924
-d "{ \"comment\": { \"body\": \"${body//\"/}\", \"notify\": \"\", \"content-type\": \"text\", \"isprivate\": false } }" )
2025

21-
echo "$response"
26+
log::message "$response"
2227
}
2328

2429
teamwork::pull_request_opened() {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"action": "submitted",
3+
"number": 1,
4+
"pull_request": {
5+
"body": "This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456",
6+
"head": {
7+
"repo": {
8+
"full_name": "teamwork/github-sync"
9+
}
10+
},
11+
"html_url": "https://github.com/teamwork/github-sync/pull/2",
12+
"title": "This is an example of a title for the PR."
13+
},
14+
"review": {
15+
"state": "approved",
16+
"body": "This is the comment of the review."
17+
},
18+
"sender": {
19+
"login": "username"
20+
}
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"action": "closed",
3+
"number": 1,
4+
"merged": true,
5+
"pull_request": {
6+
"body": "This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456",
7+
"head": {
8+
"repo": {
9+
"full_name": "teamwork/github-sync"
10+
}
11+
},
12+
"html_url": "https://github.com/teamwork/github-sync/pull/1",
13+
"title": "This is an example of a title for the PR."
14+
},
15+
"sender": {
16+
"login": "username"
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"action": "opened",
3+
"number": 1,
4+
"pull_request": {
5+
"body": "This is the body of the PR. https://xxxx.teamwork.com/#/tasks/123 https://xxx.teamwork.com/#/tasks/456",
6+
"head": {
7+
"repo": {
8+
"full_name": "teamwork/github-sync"
9+
}
10+
},
11+
"html_url": "https://github.com/teamwork/github-sync/pull/1",
12+
"title": "This is an example of a title for the PR."
13+
},
14+
"sender": {
15+
"login": "username"
16+
}
17+
}

0 commit comments

Comments
 (0)