grim/youtrack-import

Parents 0217a2b03777
Children d740bff69232
Clean up the logging on user creation and roll it back to 5 at a time instead of 10. Fixes YI-23
--- a/youtrack/user.go Thu Jan 16 00:02:27 2020 -0600
+++ b/youtrack/user.go Thu Jan 16 01:16:43 2020 -0600
@@ -5,6 +5,7 @@
"encoding/xml"
"fmt"
"net/http"
+ "strings"
)
type User struct {
@@ -70,30 +71,48 @@
}
func (c *Client) ImportUsers(p *Project) error {
- r := 10
+ r := 5
users := []*User{}
// loop through the users we were given and create a new list based on the
// ones that we need to create.
for _, user := range p.Users {
+ fmt.Printf("checking if user %q exists ... ", user.Login)
+
exists, err := c.UserExists(user.Login)
if err != nil {
+ fmt.Printf("failed.\n")
+
return err
}
if !exists {
+ fmt.Printf("no, will be created.\n")
users = append(users, user)
+ } else {
+ fmt.Printf("yes.\n")
}
}
+ if len(users) == 0 {
+ fmt.Printf("all users exist, nothing to import.\n")
+
+ return nil
+ }
+
for s := 0; s < len(users); s += r {
e := s + r
if e > len(users) {
e = len(users)
}
- fmt.Printf("importing users %d-%d ...", s, e)
+ sUsers := make([]string, e-s)
+ for idx, user := range users[s:e] {
+ sUsers[idx] = user.Login
+ }
+
+ fmt.Printf("importing users %s ... ", strings.Join(sUsers, ", "))
if errs := c.importUsersRange(users, s, e); len(errs) > 0 {
fmt.Printf("failed.\n")