Skip to content

Commit 4f5a211

Browse files
js6pakwolfogreGiteaBot
authored
Include the GITHUB_TOKEN/GITEA_TOKEN secret for fork pull requests (#26759)
Include `GITHUB_TOKEN`/`GITEA_TOKEN` secrets for actions triggered by pull requests This makes it consistent with the environment variables which you can already access ```shell echo env: $GITHUB_TOKEN echo expression: ${{ secrets.GITHUB_TOKEN }} ``` before ![image](https://github.com/go-gitea/gitea/assets/35262707/b6f750f6-3995-40f0-b8aa-df01e7997c37) after ![image](https://github.com/go-gitea/gitea/assets/35262707/ab74464b-7638-458a-afd5-f39e6101d2cf) --------- Co-authored-by: Jason Song <[email protected]> Co-authored-by: Giteabot <[email protected]>
1 parent b91057b commit 4f5a211

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

routers/api/actions/runner/utils.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ func pickTask(ctx context.Context, runner *actions_model.ActionRunner) (*runnerv
5555

5656
func getSecretsOfTask(ctx context.Context, task *actions_model.ActionTask) map[string]string {
5757
secrets := map[string]string{}
58+
59+
secrets["GITHUB_TOKEN"] = task.Token
60+
secrets["GITEA_TOKEN"] = task.Token
61+
5862
if task.Job.Run.IsForkPullRequest && task.Job.Run.TriggerEvent != actions_module.GithubEventPullRequestTarget {
59-
// ignore secrets for fork pull request
63+
// ignore secrets for fork pull request, except GITHUB_TOKEN and GITEA_TOKEN which are automatically generated.
6064
// for the tasks triggered by pull_request_target event, they could access the secrets because they will run in the context of the base branch
6165
// see the documentation: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
6266
return secrets
@@ -82,13 +86,6 @@ func getSecretsOfTask(ctx context.Context, task *actions_model.ActionTask) map[s
8286
}
8387
}
8488

85-
if _, ok := secrets["GITHUB_TOKEN"]; !ok {
86-
secrets["GITHUB_TOKEN"] = task.Token
87-
}
88-
if _, ok := secrets["GITEA_TOKEN"]; !ok {
89-
secrets["GITEA_TOKEN"] = task.Token
90-
}
91-
9289
return secrets
9390
}
9491

0 commit comments

Comments
 (0)