Skip to content

Commit

Permalink
refactor: for upgraded versions
Browse files Browse the repository at this point in the history
  • Loading branch information
obcode committed Nov 5, 2024
1 parent fc12841 commit 8efbc5e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
24 changes: 12 additions & 12 deletions gitlab/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions gitlab/protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gitlab/seeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gitlab/setaccess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions gitlab/starterrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions gitlab/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 8efbc5e

Please sign in to comment.