Skip to content

Commit 8d93e80

Browse files
js6pakwolfogreGiteaBot
committed
Include the GITHUB_TOKEN/GITEA_TOKEN secret for fork pull requests (go-gitea#26759)
Backport go-gitea#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 c3d323f commit 8d93e80

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
@@ -53,8 +53,12 @@ func pickTask(ctx context.Context, runner *actions_model.ActionRunner) (*runnerv
5353

5454
func getSecretsOfTask(ctx context.Context, task *actions_model.ActionTask) map[string]string {
5555
secrets := map[string]string{}
56+
57+
secrets["GITHUB_TOKEN"] = task.Token
58+
secrets["GITEA_TOKEN"] = task.Token
59+
5660
if task.Job.Run.IsForkPullRequest {
57-
// ignore secrets for fork pull request
61+
// ignore secrets for fork pull request, except GITHUB_TOKEN and GITEA_TOKEN which are automatically generated.
5862
return secrets
5963
}
6064

@@ -78,13 +82,6 @@ func getSecretsOfTask(ctx context.Context, task *actions_model.ActionTask) map[s
7882
}
7983
}
8084

81-
if _, ok := secrets["GITHUB_TOKEN"]; !ok {
82-
secrets["GITHUB_TOKEN"] = task.Token
83-
}
84-
if _, ok := secrets["GITEA_TOKEN"]; !ok {
85-
secrets["GITEA_TOKEN"] = task.Token
86-
}
87-
8885
return secrets
8986
}
9087

0 commit comments

Comments
 (0)