func updateIssueReviewLabels(client *github.Client, log log15.Logger, review ReviewRequest) error { oldLabels := []string{} newLabels := []string{review.CalculateAppropriateStatus()} foundReviewLabel, incorrectReviewLabel := false, false for _, l := range review.issue.Labels { oldLabels = append(oldLabels, *l.Name) switch *l.Name { case WIPLabel, CakedLabel, AwaitingCakeLabel: foundReviewLabel = true if *l.Name != newLabels[0] { incorrectReviewLabel = true } continue default: newLabels = append(newLabels, *l.Name) } } var labelsNeedUpdating bool switch { case !foundReviewLabel: labelsNeedUpdating = true log.Info("could not find review label", "old_labels", oldLabels, "new_labels", newLabels) case incorrectReviewLabel: labelsNeedUpdating = true log.Info("review label is incorrect", "old_labels", oldLabels, "new_labels", newLabels) default: log.Info("review label does not need updating", "labels", oldLabels) } if labelsNeedUpdating { _, _, err := client.Issues.ReplaceLabelsForIssue(*review.repo.Owner.Login, *review.repo.Name, review.Number(), newLabels) if err != nil { log.Error("unable to update issue review label", "err", err) return err } } return nil }
// NewRaft returns a new raft struct based on the provided configuration func NewRaft(config *Config, logger log.Logger) (*Raft, error) { rand.Seed(time.Now().Unix()) if config.StateMachine == nil { return nil, fmt.Errorf("No state machine configured.") } inbox := make(chan *channelCmd, 4096) // set advertise address, if set advertise := config.Bind if len(config.Advertise) > 0 { advertise = config.Advertise } logger = logger.New("module", "raft", "server", advertise) // cleanup old directories if len(config.Peers) != 0 { err := os.RemoveAll(config.BaseDir) if err != nil { return nil, err } } // create basic directories err := os.MkdirAll(config.BaseDir, os.FileMode(0700)) err = createDirs(config.BaseDir) if err != nil { logger.Error("Can not create directories", "error", err.Error()) return nil, err } // create stable stable, err := newBoltDBStable(fmt.Sprintf("%s/logs", config.BaseDir), logger) raftRPCImpl := newRaftRPC(logger, inbox) // create raft rpc server rpcServer, err := multiserver.NewRPCServer(config.Bind, codecFunc, raftRPCImpl, config.TLSConfig, logger) if err != nil { logger.Error("Can not create rpc server", "error", err.Error()) return nil, err } client := NewClient(config.ClientTLSConfig) // create peer list without itself // at the moment the config is static // and needs restart for changes peers := make(map[string]*peer) for _, server := range config.Peers { // check if this instance is in the list if server != advertise { p := &peer{ addr: server, timeoutCh: make(chan bool), syncing: false, } peers[server] = p } } chMap := &channelMap{ responseWaiter: make(map[uint64]chan interface{}), responseResult: make(map[uint64]interface{}), } vRaft := &Raft{ peers: peers, state: Shutdown, client: client, appendResCh: make(chan *ResponseAppendEntry, 4096), commitCh: make(chan uint64, 4096), inbox: inbox, config: config, channelMap: chMap, stable: stable, logger: logger, advertise: advertise, rpcServer: rpcServer, bind: config.Bind, fsm: config.StateMachine, voteRespCh: make(chan *ResponseVote, len(peers)), commandCh: make(chan *channelCmd, 4096), leaderCh: make(chan string, 5), raftRPC: raftRPCImpl, } vRaft.workingSnapshot = &fsmSnapshot{ LastIndex: 0, LastTerm: 0, } return vRaft, nil }