Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire webhooks when repo is created from a template #11534

Closed
2 of 7 tasks
joshbalfour opened this issue May 21, 2020 · 10 comments
Closed
2 of 7 tasks

Fire webhooks when repo is created from a template #11534

joshbalfour opened this issue May 21, 2020 · 10 comments

Comments

@joshbalfour
Copy link

  • Gitea version (or commit ref): 0b8b81e
  • Git version:
  • Operating system: arch
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

As requested from #9126
Currently webhooks aren't being fired when a repository is created from a template.
The same webhooks which are fired when a repository is created not via a template should be fired.

@lunny lunny added the type/bug label May 21, 2020
@lunny lunny added this to the 1.12.0 milestone May 21, 2020
@mrsdizzie
Copy link
Member

Looking at this, when I create repo from a template I get a 'repo created' webhook same as if I use the Web site. I'm not sure how to reproduce this or whats expected/not working.

I guess to be clear we only support repo created webhooks for organization owned repos and not individual users as far as I can tell:

func (m *webhookNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
// Add to hook queue for created repo after session commit.
if u.IsOrganization() {
if err := webhook_module.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated,
Repository: repo.APIFormat(models.AccessModeOwner),
Organization: u.APIFormat(),
Sender: doer.APIFormat(),
}); err != nil {
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
}
}
}

Is there a more detailed description of whats expected vs whats happening?

@ptman
Copy link
Contributor

ptman commented Jun 10, 2020

so not an issue?

@joshbalfour
Copy link
Author

sorry fired this off in a rush, the ‘push’ event is the one I’m thinking of:
I have a system webhook, it gets triggered with a ‘push’ event if you create a new repo but not if you create a new repo from a template.

@mrsdizzie
Copy link
Member

Create repository is not a push event, so if all you have checked is 'push events' for Webhook it should not fire a hook if you create a new repository from the Web interface. It is a "repository" event as shown in the previously mentioned code:

func (m *webhookNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
// Add to hook queue for created repo after session commit.
if u.IsOrganization() {
if err := webhook_module.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
Action: api.HookRepoCreated,
Repository: repo.APIFormat(models.AccessModeOwner),
Organization: u.APIFormat(),
Sender: doer.APIFormat(),
}); err != nil {
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
}
}
}

And if you look at a hook sent for creating a repo it will have X-Gitea-Event: repository

Unless you have a specific set of steps to reproduce creating a repository causing a created repo hook to be sent with a push type?

@jolheiser
Copy link
Member

When commits are created via repo creation (template or not), this function is used to set the environment, which would stop hooks from firing.

// InternalPushingEnvironment returns an os environment to switch off hooks on push
// It is recommended to avoid using this unless you are pushing within a transaction
// or if you absolutely are sure that post-receive and pre-receive will do nothing
// We provide the full pushing-environment for other hook providers
func InternalPushingEnvironment(doer *User, repo *Repository) []string {
return append(PushingEnvironment(doer, repo),
EnvIsInternal+"=true",
)
}

gitea/cmd/hook.go

Lines 136 to 139 in 0b8b81e

func runHookPreReceive(c *cli.Context) error {
if os.Getenv(models.EnvIsInternal) == "true" {
return nil
}

gitea/cmd/hook.go

Lines 271 to 274 in 0b8b81e

func runHookPostReceive(c *cli.Context) error {
if os.Getenv(models.EnvIsInternal) == "true" {
return nil
}

I believe you could get a push event to fire if using the push-create feature, however.

@mrsdizzie
Copy link
Member

Push event will trigger when use push to create and files are added, which seems right in the sense that somebody actually ran 'git push' in that situation. The create repo hook is still not a push event, but Gitea will consider the file commits (if there are any) as separate push events in that scenario -- they were manually pushed so that seems somewhat correct.

So if something should be triggered specifically by repo creation it should look for repository event which is what the 'repo creation' hook is considered and the only hook guaranteed to run when a new repo is created no matter how.

@joshbalfour
Copy link
Author

@mrsdizzie ahh ok, but the repo creation webhook is only supported in an organisation context - so using a system webhook, creating a repo as a user (not in an org), then expecting to see any webhook fired is expected behaviour right now? (until the work is done to support that on the user level)

If so looks like this is a feature request rather than a bug report - apologies for the confusion & back-and-forth everyone!

@jolheiser
Copy link
Member

I'm going to move this to 1.13 as it's currently intended behavior. 🙂

@jolheiser jolheiser modified the milestones: 1.12.0, 1.13.0 Jun 16, 2020
@stale
Copy link

stale bot commented Aug 16, 2020

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

@stale stale bot added the issue/stale label Aug 16, 2020
@stale
Copy link

stale bot commented Aug 31, 2020

This issue has been automatically closed because of inactivity. You can re-open it if needed.

@stale stale bot closed this as completed Aug 31, 2020
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants