Webhooks: differences between UI and API #349

Open
opened 2 years ago by benosman · 3 comments

I'm utilizing the API for a gitea terraform provider (non-official), and I notice some differences between repo web hooks created in the UI vs the API.

The http_method seem to be missing from the API, both in read and write operations:

Then the events field, only allows a simple list of events, it seems to ignore the trigger options available in the GUI to:

push_only (Push events),
send_everything (All events),
choose_events (Custom events...)

If push_only or send_everything are set in the GUI, the API GET returns an empty event list, and there is no way to set these triggers (that I can find) through the API.

Am I missing something, or are there plans to synchronise this functionality?

Update: one other thing to note, is that in the GUI it is possible to edit the secret without re-creating the webhook, but the API/SDK does not update the secret with the PATCH operation.

I'm utilizing the API for a gitea terraform provider (non-official), and I notice some differences between repo web hooks created in the UI vs the API. The http_method seem to be missing from the API, both in read and write operations: Then the events field, only allows a simple list of events, it seems to ignore the trigger options available in the GUI to: push_only (Push events), send_everything (All events), choose_events (Custom events...) If push_only or send_everything are set in the GUI, the API GET returns an empty event list, and there is no way to set these triggers (that I can find) through the API. Am I missing something, or are there plans to synchronise this functionality? Update: one other thing to note, is that in the GUI it is possible to edit the secret without re-creating the webhook, but the API/SDK does not update the secret with the PATCH operation.
6543 added the
upstream/gitea
label 2 years ago
Collaborator

I'll have a look what can be done throu SDK and what has to be done upstream

I'll have a look what can be done throu SDK and what has to be done upstream
6543 self-assigned this 1 year ago

Hello,
I have been able to successfully create Webhooks using the UI but I am not able to replicate the same using SDK.

Gitea version: v1.15.3

UI:

Under Site Administration:
a) Default webhooks,
b) System webhooks

image

And At Repo level in settings,
c) Repository level webhooks

image

Whereas the API has the following functions:

SDK:

func (c *Client) CreateOrgHook(org string, opt CreateHookOption) (*Hook, *Response, error)
func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, *Response, error)

type CreateHookOption struct {
	Type         HookType          `json:"type"`
	Config       map[string]string `json:"config"`
	Events       []string          `json:"events"`
	BranchFilter string            `json:"branch_filter"`
	Active       bool              `json:"active"`
}

Based on this, I have the following questions:

a) How should the Webhook Target URL, Trigger On fields be set in the Struct?

b) How can System/Default Webhooks be created using the SDK?

c) Is it possible to create Org Level Hooks from the UI?

Hello, I have been able to successfully create Webhooks using the UI but I am not able to replicate the same using SDK. Gitea version: v1.15.3 ### UI: Under Site Administration: a) Default webhooks, b) System webhooks ![image](/attachments/401d2b3f-3e0a-4649-afb4-d77216263a2c) And At Repo level in settings, c) Repository level webhooks ![image](/attachments/8577b593-b00a-4eda-95b1-dbfcaaeb3be3) Whereas the API has the following functions: ### SDK: ``` func (c *Client) CreateOrgHook(org string, opt CreateHookOption) (*Hook, *Response, error) func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, *Response, error) type CreateHookOption struct { Type HookType `json:"type"` Config map[string]string `json:"config"` Events []string `json:"events"` BranchFilter string `json:"branch_filter"` Active bool `json:"active"` } ``` Based on this, I have the following questions: a) How should the `Webhook Target URL`, `Trigger On` fields be set in the Struct? b) How can System/Default Webhooks be created using the SDK? c) Is it possible to create Org Level Hooks from the UI?

I found the OrgWebhooks also in the UI and was able to create them using the UI

Tried looking into the gitea codebase to understand how the createOrgWebhook request should be submitted using the SDK, and I came up with the below approach

	const (
		json_content_type = "json"
		hookName          = "my-webhook"
	)


	events := []string{"push"}

	hookCfg := map[string]string{
			"url":          webhookURL,
			"content_type": json_content_type,
			"name":         hookName,
	}

	_, createResp, createErr := giteaClient.CreateOrgHook(organisation, gitea.CreateHookOption{
			Type:         gitea.HookTypeGogs,
			BranchFilter: "*",
			Config:       hookCfg,
			Active:       true,
			Events:       events,
		})
	log.Info("OrgWebhook creation request for Org: ", organisation, " URL:", webhookURL, " returned status:", createResp.StatusCode)

This however sets Custom Events section as the Webhook Trigger on Critera and marks "Push" events. I was not able to figure out how to set "Push Events" as the "Trigger On" criteria instead of "Custom -> Push"

However, I believe both are equivalent ; and hence this solution is good enough

I found the OrgWebhooks also in the UI and was able to create them using the UI Tried looking into the gitea codebase to understand how the createOrgWebhook request should be submitted using the SDK, and I came up with the below approach ``` const ( json_content_type = "json" hookName = "my-webhook" ) events := []string{"push"} hookCfg := map[string]string{ "url": webhookURL, "content_type": json_content_type, "name": hookName, } _, createResp, createErr := giteaClient.CreateOrgHook(organisation, gitea.CreateHookOption{ Type: gitea.HookTypeGogs, BranchFilter: "*", Config: hookCfg, Active: true, Events: events, }) log.Info("OrgWebhook creation request for Org: ", organisation, " URL:", webhookURL, " returned status:", createResp.StatusCode) ``` This however sets Custom Events section as the Webhook Trigger on Critera and marks "Push" events. I was not able to figure out how to set "Push Events" as the "Trigger On" criteria instead of "Custom -> Push" However, I believe both are equivalent ; and hence this solution is good enough
Sign in to join this conversation.
No Milestone
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: gitea/go-sdk#349
Loading…
There is no content yet.