Skip to content

Commit

Permalink
fix(webhook): Fix parsing hooks from several providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Porsh33 committed Apr 11, 2022
1 parent 82d39e1 commit 2ae0dd8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 0 additions & 3 deletions server/service/githook/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ func (p *parser) Parse(req *http.Request, secretFunc func(string) *core.Reposito
}

payload, err := p.client.Webhooks.Parse(req, fn)
if err == scm.ErrUnknownEvent {
return nil, nil, nil
}
if err != nil {
return nil, nil, err
}
Expand Down
15 changes: 15 additions & 0 deletions server/store/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,21 @@ func filterHooks(hooks []*scm.Hook, provider core.Provider) []*scm.Hook {
for _, hook := range hooks {
url, _ := url.Parse(hook.Target)
if strings.HasPrefix(hook.Target, provider.Host) && strings.HasSuffix(url.Path, "/webhooks") {
if provider.Name == "stash" {
stashMap := map[string]string{
"pr:merged": "pull_request",
"pr:modified": "pull_request",
"pr:opened": "pull_request",
"repo:refs_changed": "push",
}
mappedEvents := make([]string, 0)
for _, event := range hook.Events {
if stashMap[event] != "" {
mappedEvents = append(mappedEvents, stashMap[event])
}
}
hook.Events = mappedEvents
}
webhooks = append(webhooks, hook)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export class ProvidersModalComponent implements OnInit {

this.error = null;
this.saving = true;
console.log('im here');
console.log(this.form.controls);
let data: any = {
name: this.form.controls.name.value,
url: this.form.controls.url.value,
Expand Down

0 comments on commit 2ae0dd8

Please sign in to comment.