-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: test | ||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
- name: Post comment | ||
run: go run ./cmd/gh-pr-comment "Test from GitHub Actions" "Comment from GitHub Actions" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package githubactions | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/at-wat/gh-pr-comment/pkg/cienv" | ||
) | ||
|
||
func init() { | ||
cienv.Register(&Actions{}) | ||
} | ||
|
||
type Actions struct { | ||
} | ||
|
||
func (t *Actions) Name() string { | ||
return "GitHub Actions" | ||
} | ||
|
||
func (t *Actions) Detect() (*cienv.CIEnv, error) { | ||
env := &cienv.CIEnv{} | ||
|
||
if isActions, ok := os.LookupEnv("GITHUB_ACTIONS"); !ok || isActions != "true" { | ||
return nil, cienv.ErrNotDetected | ||
} | ||
|
||
eventName, ok := os.LookupEnv("GITHUB_EVENT_NAME") | ||
if !ok { | ||
return nil, errors.New("GITHUB_EVENT_NAME is not set") | ||
} | ||
env.IsPullRequest = eventName == "pull_request" | ||
|
||
if env.IsPullRequest { | ||
if prEvent, ok := os.LookupEnv("GITHUB_EVENT_PATH"); ok { | ||
f, err := os.Open(prEvent) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read event payload: %w", err) | ||
} | ||
defer f.Close() | ||
dec := json.NewDecoder(f) | ||
|
||
var event pullRequestEvent | ||
if err := dec.Decode(&event); err != nil { | ||
return nil, fmt.Errorf("failed to parse event payload: %w", err) | ||
} | ||
|
||
env.PullRequest = event.Number | ||
env.PullRequestSlug, err = cienv.NewSlug(event.PullRequest.Head.Repo.FullName) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse head.repo.full_name: %w", err) | ||
} | ||
} else { | ||
return nil, errors.New("GITHUB_EVENT_PATH is not set") | ||
} | ||
} | ||
|
||
if slug, ok := os.LookupEnv("GITHUB_REPOSITORY"); ok { | ||
var err error | ||
env.RepoSlug, err = cienv.NewSlug(slug) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse GITHUB_REPOSITORY: %w", err) | ||
} | ||
} | ||
|
||
return env, nil | ||
} | ||
|
||
type pullRequestEvent struct { | ||
Action string `json:"action"` | ||
Number int `json:"number"` | ||
PullRequest struct { | ||
Head struct { | ||
Repo struct { | ||
FullName string `json:"full_name"` | ||
} `json:"repo"` | ||
} `json:"head"` | ||
} `json:"pull_request"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package travis | ||
package travisci | ||
|
||
import ( | ||
"errors" | ||
|