Skip to content

Commit

Permalink
Merge pull request #333 from reviewdog/github-check-reporter
Browse files Browse the repository at this point in the history
Implement github-check reporter
  • Loading branch information
haya14busa committed Sep 29, 2019
2 parents 81f21e9 + ba13201 commit b7ebbbc
Show file tree
Hide file tree
Showing 11 changed files with 409 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reviewdog.yml
@@ -1,4 +1,4 @@
name: reviewdog on GitHub Action
name: reviewdog on Pull Request
on: [pull_request]
jobs:
reviewdog:
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/reviewdog_on_push.yml
@@ -0,0 +1,39 @@
name: reviewdog on Push
on: [push]
jobs:
reviewdog-:
name: reviewdog-
runs-on: ubuntu-latest
steps:
- name: Dump GitHub Context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "${GITHUB_CONTEXT}"

- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go

- name: Add $GOPATH/bin
run: |
echo ::add-path::$(go env GOPATH)/bin
- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Install linters
run: '( cd linters && go get golang.org/x/lint/golint )'

- name: Setup reviewdog
run: |
# mkdir -p $HOME/bin && curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b $HOME/bin
# echo ::add-path::$HOME/bin
go install ./cmd/reviewdog
- name: Run reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
golint ./... | reviewdog -f=golint -name=golint-github-check -reporter=github-check -level=warning
224 changes: 224 additions & 0 deletions cienv/_testdata/github_event_push.json
@@ -0,0 +1,224 @@
{
"after": "febdd4bf26c6e8856c792303cfc66fa5e7bc975b",
"base_ref": null,
"before": "7a17ca64b1febe0a4479161cbe72978d6666f424",
"commits": [
{
"added": [],
"author": {
"email": "haya14busa@gmail.com",
"name": "haya14busa",
"username": "haya14busa"
},
"committer": {
"email": "haya14busa@gmail.com",
"name": "haya14busa",
"username": "haya14busa"
},
"distinct": true,
"id": "8bc5e712cca1bf1b2e35df4a87405b16e085a084",
"message": "chagne tool name for golint with reviewdog on push",
"modified": [
".github/workflows/reviewdog_on_push.yml"
],
"removed": [],
"timestamp": "2019-09-29T13:46:46Z",
"tree_id": "84b30c9ea4a8ca1aba03c85ffcd1b9f225d56a66",
"url": "https://github.com/reviewdog/reviewdog/commit/8bc5e712cca1bf1b2e35df4a87405b16e085a084"
},
{
"added": [],
"author": {
"email": "haya14busa@gmail.com",
"name": "haya14busa",
"username": "haya14busa"
},
"committer": {
"email": "haya14busa@gmail.com",
"name": "haya14busa",
"username": "haya14busa"
},
"distinct": true,
"id": "febdd4bf26c6e8856c792303cfc66fa5e7bc975b",
"message": "Dump GitHub Context in on push workflow",
"modified": [
".github/workflows/reviewdog_on_push.yml"
],
"removed": [],
"timestamp": "2019-09-29T13:47:21Z",
"tree_id": "83e3cb65fa825f47f618fd1b9c49d5d949831d6f",
"url": "https://github.com/reviewdog/reviewdog/commit/febdd4bf26c6e8856c792303cfc66fa5e7bc975b"
}
],
"compare": "https://github.com/reviewdog/reviewdog/compare/7a17ca64b1fe...febdd4bf26c6",
"created": false,
"deleted": false,
"forced": false,
"head_commit": {
"added": [],
"author": {
"email": "haya14busa@gmail.com",
"name": "haya14busa",
"username": "haya14busa"
},
"committer": {
"email": "haya14busa@gmail.com",
"name": "haya14busa",
"username": "haya14busa"
},
"distinct": true,
"id": "febdd4bf26c6e8856c792303cfc66fa5e7bc975b",
"message": "Dump GitHub Context in on push workflow",
"modified": [
".github/workflows/reviewdog_on_push.yml"
],
"removed": [],
"timestamp": "2019-09-29T13:47:21Z",
"tree_id": "83e3cb65fa825f47f618fd1b9c49d5d949831d6f",
"url": "https://github.com/reviewdog/reviewdog/commit/febdd4bf26c6e8856c792303cfc66fa5e7bc975b"
},
"organization": {
"avatar_url": "https://avatars2.githubusercontent.com/u/48765237?v=4",
"description": "",
"events_url": "https://api.github.com/orgs/reviewdog/events",
"hooks_url": "https://api.github.com/orgs/reviewdog/hooks",
"id": 48765237,
"issues_url": "https://api.github.com/orgs/reviewdog/issues",
"login": "reviewdog",
"members_url": "https://api.github.com/orgs/reviewdog/members{/member}",
"node_id": "MDEyOk9yZ2FuaXphdGlvbjQ4NzY1MjM3",
"public_members_url": "https://api.github.com/orgs/reviewdog/public_members{/member}",
"repos_url": "https://api.github.com/orgs/reviewdog/repos",
"url": "https://api.github.com/orgs/reviewdog"
},
"pusher": {
"email": "hayabusa1419@gmail.com",
"name": "haya14busa"
},
"ref": "refs/heads/github-check-reporter",
"repository": {
"archive_url": "https://api.github.com/repos/reviewdog/reviewdog/{archive_format}{/ref}",
"archived": false,
"assignees_url": "https://api.github.com/repos/reviewdog/reviewdog/assignees{/user}",
"blobs_url": "https://api.github.com/repos/reviewdog/reviewdog/git/blobs{/sha}",
"branches_url": "https://api.github.com/repos/reviewdog/reviewdog/branches{/branch}",
"clone_url": "https://github.com/reviewdog/reviewdog.git",
"collaborators_url": "https://api.github.com/repos/reviewdog/reviewdog/collaborators{/collaborator}",
"comments_url": "https://api.github.com/repos/reviewdog/reviewdog/comments{/number}",
"commits_url": "https://api.github.com/repos/reviewdog/reviewdog/commits{/sha}",
"compare_url": "https://api.github.com/repos/reviewdog/reviewdog/compare/{base}...{head}",
"contents_url": "https://api.github.com/repos/reviewdog/reviewdog/contents/{+path}",
"contributors_url": "https://api.github.com/repos/reviewdog/reviewdog/contributors",
"created_at": 1476705514,
"default_branch": "master",
"deployments_url": "https://api.github.com/repos/reviewdog/reviewdog/deployments",
"description": ":dog: Automated code review tool integrated with any code analysis tools regardless of programming language",
"disabled": false,
"downloads_url": "https://api.github.com/repos/reviewdog/reviewdog/downloads",
"events_url": "https://api.github.com/repos/reviewdog/reviewdog/events",
"fork": false,
"forks": 70,
"forks_count": 70,
"forks_url": "https://api.github.com/repos/reviewdog/reviewdog/forks",
"full_name": "reviewdog/reviewdog",
"git_commits_url": "https://api.github.com/repos/reviewdog/reviewdog/git/commits{/sha}",
"git_refs_url": "https://api.github.com/repos/reviewdog/reviewdog/git/refs{/sha}",
"git_tags_url": "https://api.github.com/repos/reviewdog/reviewdog/git/tags{/sha}",
"git_url": "git://github.com/reviewdog/reviewdog.git",
"has_downloads": true,
"has_issues": true,
"has_pages": false,
"has_projects": true,
"has_wiki": true,
"homepage": "https://medium.com/@haya14busa/reviewdog-a-code-review-dog-who-keeps-your-codebase-healthy-d957c471938b#.8xctbaw5u",
"hooks_url": "https://api.github.com/repos/reviewdog/reviewdog/hooks",
"html_url": "https://github.com/reviewdog/reviewdog",
"id": 71133469,
"issue_comment_url": "https://api.github.com/repos/reviewdog/reviewdog/issues/comments{/number}",
"issue_events_url": "https://api.github.com/repos/reviewdog/reviewdog/issues/events{/number}",
"issues_url": "https://api.github.com/repos/reviewdog/reviewdog/issues{/number}",
"keys_url": "https://api.github.com/repos/reviewdog/reviewdog/keys{/key_id}",
"labels_url": "https://api.github.com/repos/reviewdog/reviewdog/labels{/name}",
"language": "Go",
"languages_url": "https://api.github.com/repos/reviewdog/reviewdog/languages",
"license": {
"key": "mit",
"name": "MIT License",
"node_id": "MDc6TGljZW5zZTEz",
"spdx_id": "MIT",
"url": "https://api.github.com/licenses/mit"
},
"master_branch": "master",
"merges_url": "https://api.github.com/repos/reviewdog/reviewdog/merges",
"milestones_url": "https://api.github.com/repos/reviewdog/reviewdog/milestones{/number}",
"mirror_url": null,
"name": "reviewdog",
"node_id": "MDEwOlJlcG9zaXRvcnk3MTEzMzQ2OQ==",
"notifications_url": "https://api.github.com/repos/reviewdog/reviewdog/notifications{?since,all,participating}",
"open_issues": 27,
"open_issues_count": 27,
"organization": "reviewdog",
"owner": {
"avatar_url": "https://avatars2.githubusercontent.com/u/48765237?v=4",
"email": null,
"events_url": "https://api.github.com/users/reviewdog/events{/privacy}",
"followers_url": "https://api.github.com/users/reviewdog/followers",
"following_url": "https://api.github.com/users/reviewdog/following{/other_user}",
"gists_url": "https://api.github.com/users/reviewdog/gists{/gist_id}",
"gravatar_id": "",
"html_url": "https://github.com/reviewdog",
"id": 48765237,
"login": "reviewdog",
"name": "reviewdog",
"node_id": "MDEyOk9yZ2FuaXphdGlvbjQ4NzY1MjM3",
"organizations_url": "https://api.github.com/users/reviewdog/orgs",
"received_events_url": "https://api.github.com/users/reviewdog/received_events",
"repos_url": "https://api.github.com/users/reviewdog/repos",
"site_admin": false,
"starred_url": "https://api.github.com/users/reviewdog/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/reviewdog/subscriptions",
"type": "Organization",
"url": "https://api.github.com/users/reviewdog"
},
"private": false,
"pulls_url": "https://api.github.com/repos/reviewdog/reviewdog/pulls{/number}",
"pushed_at": 1569764859,
"releases_url": "https://api.github.com/repos/reviewdog/reviewdog/releases{/id}",
"size": 4533,
"ssh_url": "git@github.com:reviewdog/reviewdog.git",
"stargazers": 1217,
"stargazers_count": 1217,
"stargazers_url": "https://api.github.com/repos/reviewdog/reviewdog/stargazers",
"statuses_url": "https://api.github.com/repos/reviewdog/reviewdog/statuses/{sha}",
"subscribers_url": "https://api.github.com/repos/reviewdog/reviewdog/subscribers",
"subscription_url": "https://api.github.com/repos/reviewdog/reviewdog/subscription",
"svn_url": "https://github.com/reviewdog/reviewdog",
"tags_url": "https://api.github.com/repos/reviewdog/reviewdog/tags",
"teams_url": "https://api.github.com/repos/reviewdog/reviewdog/teams",
"trees_url": "https://api.github.com/repos/reviewdog/reviewdog/git/trees{/sha}",
"updated_at": "2019-09-29T11:53:30Z",
"url": "https://github.com/reviewdog/reviewdog",
"watchers": 1217,
"watchers_count": 1217
},
"sender": {
"avatar_url": "https://avatars0.githubusercontent.com/u/3797062?v=4",
"events_url": "https://api.github.com/users/haya14busa/events{/privacy}",
"followers_url": "https://api.github.com/users/haya14busa/followers",
"following_url": "https://api.github.com/users/haya14busa/following{/other_user}",
"gists_url": "https://api.github.com/users/haya14busa/gists{/gist_id}",
"gravatar_id": "",
"html_url": "https://github.com/haya14busa",
"id": 3797062,
"login": "haya14busa",
"node_id": "MDQ6VXNlcjM3OTcwNjI=",
"organizations_url": "https://api.github.com/users/haya14busa/orgs",
"received_events_url": "https://api.github.com/users/haya14busa/received_events",
"repos_url": "https://api.github.com/users/haya14busa/repos",
"site_admin": false,
"starred_url": "https://api.github.com/users/haya14busa/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/haya14busa/subscriptions",
"type": "User",
"url": "https://api.github.com/users/haya14busa"
}
}
6 changes: 6 additions & 0 deletions cienv/github_actions.go
Expand Up @@ -19,6 +19,9 @@ type GitHubEvent struct {
After string `json:"after"`
PullRequests []GitHubPullRequest `json:"pull_requests"`
} `json:"check_suite"`
HeadCommit struct {
ID string `json:"id"`
} `json:"head_commit"`
}

type GitHubPullRequest struct {
Expand Down Expand Up @@ -60,6 +63,9 @@ func getBuildInfoFromGitHubActionEventPath(eventPath string) (*BuildInfo, bool,
info.Branch = pr.Head.Ref
info.SHA = pr.Head.Sha
}
if info.SHA == "" {
info.SHA = event.HeadCommit.ID
}
return info, info.PullRequest != 0, nil
}

Expand Down
11 changes: 11 additions & 0 deletions cienv/github_actions_test.go
Expand Up @@ -27,3 +27,14 @@ func TestGetBuildInfoFromGitHubActionEventPath_rerunevent(t *testing.T) {
t.Errorf("result has diff:\n%s", diff)
}
}

func TestGetBuildInfoFromGitHubActionEventPath_pushevent(t *testing.T) {
got, _, err := getBuildInfoFromGitHubActionEventPath("_testdata/github_event_push.json")
if err != nil {
t.Fatal(err)
}
want := &BuildInfo{Owner: "reviewdog", Repo: "reviewdog", SHA: "febdd4bf26c6e8856c792303cfc66fa5e7bc975b"}
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("result has diff:\n%s", diff)
}
}
4 changes: 2 additions & 2 deletions cmd/reviewdog/doghouse.go
Expand Up @@ -20,12 +20,12 @@ import (
"golang.org/x/sync/errgroup"
)

func runDoghouse(ctx context.Context, r io.Reader, w io.Writer, opt *option, isProject bool) error {
func runDoghouse(ctx context.Context, r io.Reader, w io.Writer, opt *option, isProject bool, allowNonPR bool) error {
ghInfo, isPr, err := cienv.GetBuildInfo()
if err != nil {
return err
}
if !isPr {
if !isPr && !allowNonPR {
fmt.Fprintln(os.Stderr, "reviewdog: this is not PullRequest build.")
return nil
}
Expand Down
17 changes: 13 additions & 4 deletions cmd/reviewdog/main.go
Expand Up @@ -67,12 +67,15 @@ const (
runnersDoc = `comma separated runners name to run in config file. default: run all runners`
levelDoc = `report level currently used for github-pr-check reporter ("info","warning","error").`
guessPullRequestDoc = `guess Pull Request ID by branch name and commit SHA`
reporterDoc = `reporter of reviewdog results. (local, github-pr-check, github-pr-review, gitlab-mr-discussion, gitlab-mr-commit)
reporterDoc = `reporter of reviewdog results. (local, github-check, github-pr-check, github-pr-review, gitlab-mr-discussion, gitlab-mr-commit)
"local" (default)
Report results to stdout.
"github-pr-check" (experimental)
Report results to GitHub PullRequest Check tab.
"github-check" (experimental)
Report results to GitHub Check. It works both for Pull Requests and commits
and this reporter reports all results regardless of it's new result or not.
You can see report results in GitHub PullRequest Check tab for Pull Request.
There are two options to use this reporter.
Option 1) Run reviewdog from GitHub Actions w/ secrets.GITHUB_TOKEN
Expand All @@ -91,6 +94,10 @@ const (
Note: Token is not required if you run reviewdog in Travis CI.
"github-pr-check" (experimental)
Same as github-check reporter but it only supports Pull Requests and
reports only new results which is in diff.
"github-pr-review"
Report results to GitHub review comments.
Expand Down Expand Up @@ -198,8 +205,10 @@ See -reporter flag for migration and set -reporter="github-pr-review" or -report
switch opt.reporter {
default:
return fmt.Errorf("unknown -reporter: %s", opt.reporter)
case "github-check":
return runDoghouse(ctx, r, w, opt, isProject, true)
case "github-pr-check":
return runDoghouse(ctx, r, w, opt, isProject)
return runDoghouse(ctx, r, w, opt, isProject, false)
case "github-pr-review":
if os.Getenv("REVIEWDOG_GITHUB_API_TOKEN") == "" {
fmt.Fprintln(os.Stderr, "REVIEWDOG_GITHUB_API_TOKEN is not set")
Expand Down

0 comments on commit b7ebbbc

Please sign in to comment.