From 8efbc5e1ac2568546498a7860c4df2907c2b8d87 Mon Sep 17 00:00:00 2001 From: Oliver Braun Date: Tue, 5 Nov 2024 15:21:26 +0100 Subject: [PATCH] refactor: for upgraded versions --- gitlab/projects.go | 24 ++++++++++++------------ gitlab/protect.go | 8 ++++---- gitlab/seeder.go | 2 +- gitlab/setaccess.go | 2 +- gitlab/starterrepo.go | 6 +++--- gitlab/users.go | 8 ++++---- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/gitlab/projects.go b/gitlab/projects.go index 579e606..f31a828 100644 --- a/gitlab/projects.go +++ b/gitlab/projects.go @@ -12,16 +12,16 @@ import ( func (c *Client) generateProject(assignmentCfg *config.AssignmentConfig, name string, inID int) (*gitlab.Project, bool, error) { generated := false p := &gitlab.CreateProjectOptions{ - Name: gitlab.String(name), - Description: gitlab.String(assignmentCfg.Description), - NamespaceID: gitlab.Int(inID), - MergeRequestsAccessLevel: gitlab.AccessControl("enabled"), - IssuesAccessLevel: gitlab.AccessControl("enabled"), - BuildsAccessLevel: gitlab.AccessControl("enabled"), - JobsEnabled: gitlab.Bool(true), - Visibility: gitlab.Visibility(gitlab.PrivateVisibility), - ContainerRegistryEnabled: gitlab.Bool(assignmentCfg.ContainerRegistry), - OnlyAllowMergeIfAllStatusChecksPassed: gitlab.Bool(false), + Name: gitlab.Ptr(name), + Description: gitlab.Ptr(assignmentCfg.Description), + NamespaceID: gitlab.Ptr(inID), + MergeRequestsAccessLevel: gitlab.Ptr(gitlab.EnabledAccessControl), + IssuesAccessLevel: gitlab.Ptr(gitlab.EnabledAccessControl), + BuildsAccessLevel: gitlab.Ptr(gitlab.EnabledAccessControl), + JobsEnabled: gitlab.Ptr(true), + Visibility: gitlab.Ptr(gitlab.PrivateVisibility), + ContainerRegistryEnabled: gitlab.Ptr(assignmentCfg.ContainerRegistry), + OnlyAllowMergeIfAllStatusChecksPassed: gitlab.Ptr(false), } project, _, err := c.Projects.CreateProject(p) @@ -49,8 +49,8 @@ func (c *Client) generateProject(assignmentCfg *config.AssignmentConfig, name st func (c *Client) getProjectByName(fullpathprojectname string) (*gitlab.Project, error) { opt := &gitlab.ListProjectsOptions{ - Search: gitlab.String(fullpathprojectname), - SearchNamespaces: gitlab.Bool(true), + Search: gitlab.Ptr(fullpathprojectname), + SearchNamespaces: gitlab.Ptr(true), } projects, _, err := c.Projects.ListProjects(opt) if err != nil { diff --git a/gitlab/protect.go b/gitlab/protect.go index 56d9662..8052fe1 100644 --- a/gitlab/protect.go +++ b/gitlab/protect.go @@ -76,10 +76,10 @@ func (c *Client) protectBranch(assignmentCfg *config.AssignmentConfig, project * } opts := &gitlab.ProtectRepositoryBranchesOptions{ - Name: gitlab.String(assignmentCfg.Startercode.ToBranch), - PushAccessLevel: gitlab.AccessLevel(gitlab.MaintainerPermissions), - MergeAccessLevel: gitlab.AccessLevel(gitlab.MaintainerPermissions), - UnprotectAccessLevel: gitlab.AccessLevel(gitlab.MaintainerPermissions), + Name: gitlab.Ptr(assignmentCfg.Startercode.ToBranch), + PushAccessLevel: gitlab.Ptr(gitlab.MaintainerPermissions), + MergeAccessLevel: gitlab.Ptr(gitlab.MaintainerPermissions), + UnprotectAccessLevel: gitlab.Ptr(gitlab.MaintainerPermissions), } _, _, err = c.ProtectedBranches.ProtectRepositoryBranches(project.ID, opts) diff --git a/gitlab/seeder.go b/gitlab/seeder.go index 58f0d24..e9b379c 100644 --- a/gitlab/seeder.go +++ b/gitlab/seeder.go @@ -81,7 +81,7 @@ func (c *Client) runSeeder(assignmentCfg *cfg.AssignmentConfig, project *gitlab. if assignmentCfg.Seeder.ProtectToBranch { opts := &gitlab.ProtectRepositoryBranchesOptions{ - Name: gitlab.String(assignmentCfg.Seeder.ToBranch), + Name: gitlab.Ptr(assignmentCfg.Seeder.ToBranch), } _, _, err = c.ProtectedBranches.ProtectRepositoryBranches(project.ID, opts) diff --git a/gitlab/setaccess.go b/gitlab/setaccess.go index b42f934..adc5ed6 100644 --- a/gitlab/setaccess.go +++ b/gitlab/setaccess.go @@ -141,7 +141,7 @@ func (c *Client) setaccess(assignmentCfg *config.AssignmentConfig, func (c *Client) inviteByEmail(cfg *config.AssignmentConfig, projectID int, email string) (string, error) { m := &gitlab.InvitesOptions{ Email: &email, - AccessLevel: gitlab.AccessLevel(gitlab.AccessLevelValue(cfg.AccessLevel)), + AccessLevel: gitlab.Ptr(gitlab.AccessLevelValue(cfg.AccessLevel)), } resp, _, err := c.Invites.ProjectInvites(projectID, m) if err != nil { diff --git a/gitlab/starterrepo.go b/gitlab/starterrepo.go index 473ed97..ec09d8f 100644 --- a/gitlab/starterrepo.go +++ b/gitlab/starterrepo.go @@ -115,8 +115,8 @@ func (c *Client) devBranch(assignmentCfg *cfg.AssignmentConfig, project *gitlab. Msg("switching to development branch") opts := &gitlab.CreateBranchOptions{ - Branch: gitlab.String(assignmentCfg.Startercode.DevBranch), - Ref: gitlab.String(assignmentCfg.Startercode.ToBranch), + Branch: gitlab.Ptr(assignmentCfg.Startercode.DevBranch), + Ref: gitlab.Ptr(assignmentCfg.Startercode.ToBranch), } _, _, err := c.Branches.CreateBranch(project.ID, opts) @@ -130,7 +130,7 @@ func (c *Client) devBranch(assignmentCfg *cfg.AssignmentConfig, project *gitlab. } projectOpts := &gitlab.EditProjectOptions{ - DefaultBranch: gitlab.String(assignmentCfg.Startercode.DevBranch), + DefaultBranch: gitlab.Ptr(assignmentCfg.Startercode.DevBranch), } _, _, err = c.Projects.EditProject(project.ID, projectOpts) diff --git a/gitlab/users.go b/gitlab/users.go index 7f9c603..fcca50e 100644 --- a/gitlab/users.go +++ b/gitlab/users.go @@ -26,7 +26,7 @@ func (c *Client) getUser(student *config.Student) (*gitlab.User, error) { } options = &gitlab.ListUsersOptions{ - Search: gitlab.String(searchPattern), + Search: gitlab.Ptr(searchPattern), } users, _, err := c.Users.ListUsers(options) @@ -69,7 +69,7 @@ func (c *Client) addMember(assignmentConfig *config.AssignmentConfig, projectID, if member.AccessLevel != gitlab.AccessLevelValue(assignmentConfig.AccessLevel) { e := &gitlab.EditProjectMemberOptions{ - AccessLevel: gitlab.AccessLevel(gitlab.AccessLevelValue(assignmentConfig.AccessLevel)), + AccessLevel: gitlab.Ptr(gitlab.AccessLevelValue(assignmentConfig.AccessLevel)), } _, _, err := c.ProjectMembers.EditProjectMember(projectID, userID, e) if err != nil { @@ -83,8 +83,8 @@ func (c *Client) addMember(assignmentConfig *config.AssignmentConfig, projectID, } m := &gitlab.AddProjectMemberOptions{ - UserID: gitlab.Int(userID), - AccessLevel: gitlab.AccessLevel(gitlab.AccessLevelValue(assignmentConfig.AccessLevel)), + UserID: gitlab.Ptr(userID), + AccessLevel: gitlab.Ptr(gitlab.AccessLevelValue(assignmentConfig.AccessLevel)), } member, _, err := c.ProjectMembers.AddProjectMember(projectID, m) if err != nil {