github-pr-review: Use logging commands of GitHub Actions as Graceful degradation for Pull Request from forked repository
Ref
@@ -29,6 +29,7 @@ import (
"github.com/reviewdog/reviewdog/commands"
"github.com/reviewdog/reviewdog/project"
githubservice "github.com/reviewdog/reviewdog/service/github"
+ "github.com/reviewdog/reviewdog/service/github/githubutils"
gitlabservice "github.com/reviewdog/reviewdog/service/gitlab"
)
@@ -222,7 +223,22 @@ See -reporter flag for migration and set -reporter="github-pr-review" or -report
fmt.Fprintln(os.Stderr, "reviewdog: this is not PullRequest build.")
return nil
}
+ // If it's running in GitHub Actions and it's PR from forked repository,
+ // replace comment writer to GitHubActionLogWriter to create annotations
+ // instead of review comment because if it's PR from forked repository,
+ // GitHub token doen't have write permission due to security concern and
+ // cannot post results via Review API.
+ if cienv.IsInGitHubAction() && isPRFromForkedRepo() {
+ fmt.Fprintln(w, `reviewdog: This is Pull-Request from forked repository.
+GitHub token doesn't have write permission of Review API, so reviewdog will
+report results via logging command [1] and create annotations similar to
+github-pr-check reporter as a fallback.
+
+[1]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/development-tools-for-github-actions#logging-commands`)
+ cs = githubutils.NewGitHubActionLogWriter(opt.level)
+ } else {
cs = reviewdog.MultiCommentService(gs, cs)
+ }
ds = gs
case "gitlab-mr-discussion":
build, cli, err := gitlabBuildWithClient()
