Skip to content

Commit

Permalink
util.go: Move getUserID() and getUserIDs()
Browse files Browse the repository at this point in the history
The functions getUserID() and getUserIDs() are called by multiple files.
Move getUserID() and getUserIDs() to util.go.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
  • Loading branch information
prarit committed Mar 24, 2021
1 parent 6cfaf6c commit d118285
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
27 changes: 0 additions & 27 deletions cmd/mr_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,6 @@ func init() {
)
}

// getUser returns the userID for use with other GitLab API calls.
func getUserID(user string) *int {
if user == "" {
return nil
}
if user[0] == '@' {
user = user[1:]
}
userID, err := lab.UserIDFromUsername(user)
if err != nil {
return nil
}
if userID == -1 {
return nil
}
return gitlab.Int(userID)
}

// getUsers returns the userIDs for use with other GitLab API calls.
func getUserIDs(users []string) []int {
var ids []int
for _, a := range users {
ids = append(ids, *getUserID(a))
}
return ids
}

func verifyRemoteAndBranch(projectID int, remote string, branch string) error {
if _, err := lab.GetCommit(projectID, branch); err != nil {
return fmt.Errorf("Aborting MR create, %s:%s is not a valid target\n", remote, branch)
Expand Down
27 changes: 27 additions & 0 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,3 +602,30 @@ func same(a, b []string) bool {
}
return true
}

// getUser returns the userID for use with other GitLab API calls.
func getUserID(user string) *int {
if user == "" {
return nil
}
if user[0] == '@' {
user = user[1:]
}
userID, err := lab.UserIDFromUsername(user)
if err != nil {
return nil
}
if userID == -1 {
return nil
}
return gitlab.Int(userID)
}

// getUsers returns the userIDs for use with other GitLab API calls.
func getUserIDs(users []string) []int {
var ids []int
for _, a := range users {
ids = append(ids, *getUserID(a))
}
return ids
}

0 comments on commit d118285

Please sign in to comment.