Skip to content

Commit 08992fb

Browse files
committed
Fix webhook target url generated by actions status event
1 parent f35850f commit 08992fb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

services/webhook/notifier.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package webhook
55

66
import (
77
"context"
8+
"strings"
89

910
git_model "code.gitea.io/gitea/models/git"
1011
issues_model "code.gitea.io/gitea/models/issues"
@@ -871,14 +872,22 @@ func (m *webhookNotifier) CreateCommitStatus(ctx context.Context, repo *repo_mod
871872
return
872873
}
873874

875+
// as a webhook url, target should be an absolute url. But for internal actions target url
876+
// the target url is a url path with no host and port to make it easy to be visited
877+
// from multiple hosts. So we need to convert it to an absolute url here.
878+
target := status.TargetURL
879+
if strings.HasPrefix(target, "/") {
880+
target = setting.AppURL + strings.TrimPrefix(target, "/")
881+
}
882+
874883
payload := api.CommitStatusPayload{
875884
Context: status.Context,
876885
CreatedAt: status.CreatedUnix.AsTime().UTC(),
877886
Description: status.Description,
878887
ID: status.ID,
879888
SHA: commit.Sha1,
880889
State: status.State.String(),
881-
TargetURL: status.TargetURL,
890+
TargetURL: target,
882891

883892
Commit: apiCommit,
884893
Repo: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}),

0 commit comments

Comments
 (0)