diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2025-02-17 18:20:18 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-18 02:20:18 +0000 |
commit | 9f560d47c9516e69ffdb077658439442f40c4629 (patch) | |
tree | 23d789ecf52c712dd7beace0e3a2e1aa215d7a33 | |
parent | 15e020eec85d7ec2ef0f1e9ad10a1ffde2ca0f34 (diff) | |
download | gitea-9f560d47c9516e69ffdb077658439442f40c4629.tar.gz gitea-9f560d47c9516e69ffdb077658439442f40c4629.zip |
Make actions URL in commit status webhooks absolute (#33620)
Gitea Actions generated target url doesn't contain host and port. So we
need to include them for external webhook visiting.
Fix #33603
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
-rw-r--r-- | services/webhook/notifier.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/services/webhook/notifier.go b/services/webhook/notifier.go index 6c691c21f4..76d6fd3472 100644 --- a/services/webhook/notifier.go +++ b/services/webhook/notifier.go @@ -15,6 +15,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/httplib" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" @@ -871,6 +872,11 @@ func (m *webhookNotifier) CreateCommitStatus(ctx context.Context, repo *repo_mod return } + // as a webhook url, target should be an absolute url. But for internal actions target url + // the target url is a url path with no host and port to make it easy to be visited + // from multiple hosts. So we need to convert it to an absolute url here. + target := httplib.MakeAbsoluteURL(ctx, status.TargetURL) + payload := api.CommitStatusPayload{ Context: status.Context, CreatedAt: status.CreatedUnix.AsTime().UTC(), @@ -878,7 +884,7 @@ func (m *webhookNotifier) CreateCommitStatus(ctx context.Context, repo *repo_mod ID: status.ID, SHA: commit.Sha1, State: status.State.String(), - TargetURL: status.TargetURL, + TargetURL: target, Commit: apiCommit, Repo: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}), |