Skip to content

Commit

Permalink
fix: pipe works, small fixes left
Browse files Browse the repository at this point in the history
  • Loading branch information
omri2001 committed Nov 16, 2024
1 parent 99483db commit 37addb6
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ venv.bak/
# mkdocs documentation
/site

#mirrord config
.mirrord

# mypy
.mypy_cache/
*.iml
Expand Down
4 changes: 4 additions & 0 deletions gitlab.values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ gitlab:
ingress:
requireBasePath: false
global:
gitlab:
license:
key: license_key
secret: gitlab-license
hosts:
domain: localhost
https: false
Expand Down
58 changes: 29 additions & 29 deletions pkg/git_provider/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,16 @@ func (c *GitlabClientImpl) SetWebhook(ctx *context.Context, repo *string) (*Hook

if !ok {
addProjectHookOpts := gitlab.AddProjectHookOptions{
URL: gitlab.Ptr(c.cfg.GitProviderConfig.WebhookURL),
Token: gitlab.Ptr(c.cfg.GitProviderConfig.WebhookSecret),
URL: &c.cfg.GitProviderConfig.WebhookURL,
Token: &c.cfg.GitProviderConfig.WebhookSecret,
MergeRequestsEvents: gitlab.Ptr(true),
PushEvents: gitlab.Ptr(true),
ReleasesEvents: gitlab.Ptr(true),
TagPushEvents: gitlab.Ptr(true),
}
gitlabHook, resp, err := c.client.Projects.AddProjectHook(projectId, &addProjectHookOpts, gitlab.WithContext(*ctx))
if err != nil {
log.Println("url", *addProjectHookOpts.URL, projectId, *addProjectHookOpts.Token)
return nil, fmt.Errorf("failed to add project hook ,%d", err)
}
if resp.StatusCode != 201 {
Expand Down Expand Up @@ -273,8 +274,6 @@ func (c *GitlabClientImpl) HandlePayload(ctx *context.Context, request *http.Req
UserEmail: e.UserEmail,
OwnerID: int64(e.UserID),
}
log.Println(e.Project.Name)

case *gitlab.MergeEvent:
webhookPayload = WebhookPayload{
Event: "merge_request",
Expand Down Expand Up @@ -345,29 +344,30 @@ func (c *GitlabClientImpl) SetStatus(ctx *context.Context, repo *string, commit
}

func (c *GitlabClientImpl) PingHook(ctx *context.Context, hook *HookWithStatus) error {
if c.cfg.OrgLevelWebhook && hook.RepoName != nil {
return fmt.Errorf("trying to ping repo scope webhook while configured for org level webhook. repo: %s", *hook.RepoName)
}
if hook.RepoName == nil {
_, resp, err := c.client.Groups.GetGroupHook(c.cfg.OrgName, int(hook.HookID), nil, gitlab.WithContext(*ctx))
if err != nil {
return err
}

if resp.StatusCode == http.StatusNotFound {
return fmt.Errorf("unable to find organization webhook for hookID: %d", hook.HookID)
}
} else {
projectId := GetProjectId(ctx, c, hook.RepoName)
_, resp, err := c.client.Projects.GetProjectHook(projectId, int(hook.HookID), nil, gitlab.WithContext(*ctx))
if err != nil {
return err
}

if resp.StatusCode == http.StatusNotFound {
return fmt.Errorf("unable to find repo webhook for repo:%s hookID: %d", *hook.RepoName, hook.HookID)
}
}

return nil
panic("implement me")
//
//if c.cfg.OrgLevelWebhook && hook.RepoName != nil {
// return fmt.Errorf("trying to ping repo scope webhook while configured for org level webhook. repo: %s", *hook.RepoName)
//}
//if hook.RepoName == nil {
// _, resp, err := c.client.Groups.GetGroupHook(c.cfg.OrgName, int(hook.HookID), nil, gitlab.WithContext(*ctx))
// if err != nil {
// return err
// }
// if resp.StatusCode == http.StatusNotFound {
// return fmt.Errorf("unable to find organization webhook for hookID: %d", hook.HookID)
// }
//} else {
// projectId := GetProjectId(ctx, c, hook.RepoName)
// _, resp, err := c.client.Projects.GetProjectHook(projectId, int(hook.HookID), nil, gitlab.WithContext(*ctx))
// if err != nil {
// return err
// }
//
// if resp.StatusCode == http.StatusNotFound {
// return fmt.Errorf("unable to find repo webhook for repo:%s hookID: %d", *hook.RepoName, hook.HookID)
// }
//}
//
//return nil
}
4 changes: 4 additions & 0 deletions scripts/gitlab-setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
puts "TOKEN: #{token.token}"



#enable the Admin->Network->Outbound requests -> allow for webhooks
ApplicationSetting.current.update!(allow_local_requests_from_web_hooks_and_services: true)

# #create new group
# Group.create!(name: "Pied Pipers", path: "pied-pipers")
# g = Group.find_by(name: "Pied Pipers")
Expand Down
2 changes: 2 additions & 0 deletions scripts/init-gitlab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
set -o errexit

if [ -z "$(helm list -n gitlab | grep gitlab)" ]; then
#start gitlab namespace
kubectl create namespace gitlab
# 8. Install gitlab
helm repo add gitlab https://charts.gitlab.io/
helm upgrade --install gitlab --create-namespace -n gitlab gitlab/gitlab -f gitlab.values.yaml
Expand Down

0 comments on commit 37addb6

Please sign in to comment.