prow/plugins/assign/assign.go
func handle(h *handler) error {
	e := h.event
	org := e.Repo.Owner.Login
	repo := e.Repo.Name
	matches := h.regexp.FindAllStringSubmatch(e.Body, -1)
	if matches == nil {
		return nil
	}
	users := make(map[string]bool)
	for _, re := range matches {
		add := re[1] != "un" // un<cmd> == !add
		if re[2] == "" {
			users[e.User.Login] = add
		} else {
			for _, login := range parseLogins(re[2]) {
				users[login] = add
			}
		}
	}
	var toAdd, toRemove []string
	for login, add := range users {
		if add {
			toAdd = append(toAdd, login)
		} else {
			toRemove = append(toRemove, login)
		}
	}

	if len(toRemove) > 0 {
		h.log.Printf("Removing %s from %s/%s#%d: %v", h.userType, org, repo, e.Number, toRemove)
		if err := h.remove(org, repo, e.Number, toRemove); err != nil {
			return err
		}
	}
	if len(toAdd) > 0 {
		h.log.Printf("Adding %s to %s/%s#%d: %v", h.userType, org, repo, e.Number, toAdd)
		if err := h.add(org, repo, e.Number, toAdd); err != nil {
			if mu, ok := err.(github.MissingUsers); ok {
				msg := h.addFailureResponse(mu)
				if len(msg) == 0 {
					return nil
				}
				if err := h.gc.CreateComment(org, repo, e.Number, plugins.FormatResponseRaw(e.Body, e.HTMLURL, e.User.Login, msg)); err != nil {
					return fmt.Errorf("comment err: %v", err)
				}
				return nil
			}
			return err
		}
	}
	return nil
}
func handle(h *handler) error {
	e := h.event
	org := e.Repo.Owner.Login
	repo := e.Repo.Name
	matches := h.regexp.FindAllStringSubmatch(e.Body, -1)
	if matches == nil {
		return nil
	}
	users := make(map[string]bool)
	for _, re := range matches {
		add := re[1] != "un" // un<cmd> == !add
		if re[2] == "" {
			users[e.User.Login] = add
		} else {
			for _, login := range parseLogins(re[2]) {
				users[login] = add
			}
		}
	}
	var toAdd, toRemove []string
	for login, add := range users {
		if add {
			toAdd = append(toAdd, login)
		} else {
			toRemove = append(toRemove, login)
		}
	}

	if len(toRemove) > 0 {
		h.log.Printf("Removing %s from %s/%s#%d: %v", h.userType, org, repo, e.Number, toRemove)
		if err := h.remove(org, repo, e.Number, toRemove); err != nil {
			return err
		}
	}
	if len(toAdd) > 0 {
		h.log.Printf("Adding %s to %s/%s#%d: %v", h.userType, org, repo, e.Number, toAdd)
		if err := h.add(org, repo, e.Number, toAdd); err != nil {
			if mu, ok := err.(github.MissingUsers); ok {
				msg := h.addFailureResponse(mu)
				if len(msg) == 0 {
					return nil
				}
				if err := h.gc.CreateComment(org, repo, e.Number, plugins.FormatResponseRaw(e.Body, e.HTMLURL, e.User.Login, msg)); err != nil {
					return fmt.Errorf("comment err: %v", err)
				}
				return nil
			}
			return err
		}
	}
	return nil
}
func handle ( h * handler ) error { e := h . event org := e . Repo . Owner . Login repo := e . Repo . Name matches := h . regexp . FindAllStringSubmatch ( e . Body , - 1 ) if matches == nil { return nil } users := make ( map [ string ] bool ) for _ , re := range matches { add := re [ 1 ] != " " // un<cmd> == !add if re [ 2 ] == " " { users [ e . User . Login ] = add } else { for _ , login := range parseLogins ( re [ 2 ] ) { users [ login ] = add } } } var toAdd , toRemove [ ] string for login , add := range users { if add { toAdd = append ( toAdd , login ) } else { toRemove = append ( toRemove , login ) } } if len ( toRemove ) > 0 { h . log . Printf ( " " , h . userType , org , repo , e . Number , toRemove ) if err := h . remove ( org , repo , e . Number , toRemove ) ; err != nil { return err } } if len ( toAdd ) > 0 { h . log . Printf ( " " , h . userType , org , repo , e . Number , toAdd ) if err := h . add ( org , repo , e . Number , toAdd ) ; err != nil { if mu , ok := err . ( github . MissingUsers ) ; ok { msg := h . addFailureResponse ( mu ) if len ( msg ) == 0 { return nil } if err := h . gc . CreateComment ( org , repo , e . Number , plugins . FormatResponseRaw ( e . Body , e . HTMLURL , e . User . Login , msg ) ) ; err != nil { return fmt . Errorf ( " " , err ) } return nil } return err } } return nil }
// handle is the generic handler for the assign plugin. It uses the handler's regexp and affectedLogins
// functions to identify the users to add and/or remove and then passes the appropriate users to the
// handler's add and remove functions. If add fails to add some of the users, a response comment is
// created where the body of the response is generated by the handler's addFailureResponse function.
handle is the generic handler for the assign plugin . It uses the handler s regexp and affectedLogins functions to identify the users to add and / or remove and then passes the appropriate users to the handler s add and remove functions . If add fails to add some of the users a response comment is created where the body of the response is generated by the handler s addFailureResponse function .