Skip to content

Commit 82b92c3

Browse files
authored
[FEAT] sourcehut webhooks
(cherry picked from commit ed9dd0e)
1 parent 4ad42a4 commit 82b92c3

28 files changed

+890
-13
lines changed

modules/structs/repo.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ type Repository struct {
115115
RepoTransfer *RepoTransfer `json:"repo_transfer"`
116116
}
117117

118+
// GetName implements the gitrepo.Repository interface
119+
func (r Repository) GetName() string {
120+
return r.Name
121+
}
122+
123+
// GetOwnerName implements the gitrepo.Repository interface
124+
func (r Repository) GetOwnerName() string {
125+
return r.Owner.UserName
126+
}
127+
118128
// CreateRepoOption options when creating repository
119129
// swagger:model
120130
type CreateRepoOption struct {

modules/webhook/type.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,19 @@ type HookType = string
7373

7474
// Types of webhooks
7575
const (
76-
FORGEJO HookType = "forgejo"
77-
GITEA HookType = "gitea"
78-
GOGS HookType = "gogs"
79-
SLACK HookType = "slack"
80-
DISCORD HookType = "discord"
81-
DINGTALK HookType = "dingtalk"
82-
TELEGRAM HookType = "telegram"
83-
MSTEAMS HookType = "msteams"
84-
FEISHU HookType = "feishu"
85-
MATRIX HookType = "matrix"
86-
WECHATWORK HookType = "wechatwork"
87-
PACKAGIST HookType = "packagist"
76+
FORGEJO HookType = "forgejo"
77+
GITEA HookType = "gitea"
78+
GOGS HookType = "gogs"
79+
SLACK HookType = "slack"
80+
DISCORD HookType = "discord"
81+
DINGTALK HookType = "dingtalk"
82+
TELEGRAM HookType = "telegram"
83+
MSTEAMS HookType = "msteams"
84+
FEISHU HookType = "feishu"
85+
MATRIX HookType = "matrix"
86+
WECHATWORK HookType = "wechatwork"
87+
PACKAGIST HookType = "packagist"
88+
SOURCEHUT_BUILDS HookType = "sourcehut_builds" //nolint:revive
8889
)
8990

9091
// HookStatus is the status of a web hook

options/locale/locale_en-US.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ target_branch_not_exist = Target branch does not exist.
640640
641641
admin_cannot_delete_self = You cannot delete yourself when you are an admin. Please remove your admin privileges first.
642642
643+
required_prefix = Input must start with "%s"
644+
643645
[user]
644646
change_avatar = Change your avatar…
645647
joined_on = Joined on %s
@@ -2269,6 +2271,7 @@ settings.delete_team_tip = This team has access to all repositories and can't be
22692271
settings.remove_team_success = The team's access to the repository has been removed.
22702272
settings.add_webhook = Add webhook
22712273
settings.add_webhook.invalid_channel_name = Webhook channel name cannot be empty and cannot contain only a # character.
2274+
settings.add_webhook.invalid_path = Path must not contain a part that is "." or ".." or the empty string. It cannot start or end with a slash.
22722275
settings.hooks_desc = Webhooks automatically make HTTP POST requests to a server when certain Forgejo events trigger. Read more in the <a target="_blank" rel="noopener noreferrer" href="%s">webhooks guide</a>.
22732276
settings.webhook_deletion = Remove webhook
22742277
settings.webhook_deletion_desc = Removing a webhook deletes its settings and delivery history. Continue?
@@ -2384,6 +2387,12 @@ settings.web_hook_name_packagist = Packagist
23842387
settings.packagist_username = Packagist username
23852388
settings.packagist_api_token = API token
23862389
settings.packagist_package_url = Packagist package URL
2390+
settings.web_hook_name_sourcehut_builds = SourceHut Builds
2391+
settings.sourcehut_builds.manifest_path = Build manifest path
2392+
settings.sourcehut_builds.graphql_url = GraphQL URL (e.g. https://builds.sr.ht/query)
2393+
settings.sourcehut_builds.visibility = Job visibility
2394+
settings.sourcehut_builds.secrets = Secrets
2395+
settings.sourcehut_builds.secrets_helper = Give the job access to the build secrets (requires the SECRETS:RO grant)
23872396
settings.deploy_keys = Deploy keys
23882397
settings.add_deploy_key = Add deploy key
23892398
settings.deploy_key_desc = Deploy keys have read-only pull access to the repository.

public/assets/img/sourcehut.svg

Lines changed: 7 additions & 0 deletions
Loading

services/webhook/shared/payloader.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"crypto/sha1"
1010
"crypto/sha256"
1111
"encoding/hex"
12+
"errors"
1213
"fmt"
1314
"io"
1415
"net/http"
@@ -19,6 +20,8 @@ import (
1920
webhook_module "code.gitea.io/gitea/modules/webhook"
2021
)
2122

23+
var ErrPayloadTypeNotSupported = errors.New("unsupported webhook event")
24+
2225
// PayloadConvertor defines the interface to convert system payload to webhook payload
2326
type PayloadConvertor[T any] interface {
2427
Create(*api.CreatePayload) (T, error)

0 commit comments

Comments
 (0)