Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions constitutional.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
return res
}

func EvaluatePolls() {

Check failure on line 100 in constitutional.go

View check run for this annotation

CSH-Sonarqube-Community / SonarQube Code Analysis

constitutional.go#L100

Refactor this method to reduce its Cognitive Complexity from 44 to the 15 allowed.
ctx := context.Background()
polls, err := database.GetOpenGatekeepPolls(ctx)
if err != nil {
Expand All @@ -116,11 +116,13 @@
quorum := CalculateQuorum(*poll)

notVoted := make([]*OIDCUser, 0)
notVotedString := make([]string, 0)
votedCount := 0
// check all voters to see if they have voted
if poll.AllowedUsers == nil {
logging.Logger.WithFields(logrus.Fields{"method": "EvaluatePolls checkQuorum"}).Error(
"Users allowed to vote is nil for \"" + poll.Title + "\" !! This should not happen!!")
"Users allowed to vote is nil for \"" + poll.Title + "\" !! This should not happen!!",
)
continue
}
for _, user := range poll.AllowedUsers {
Expand All @@ -144,12 +146,29 @@
slack.MsgOptionText(
"Hello, you have not yet voted on \""+poll.Title+"\". We have not yet hit quorum"+
" and we need YOU :index_pointing_at_the_viewer: to complete your responsibility as a "+
"member of house and vote. \n"+pollLink+"\nThank you!", false))
"member of house and vote. \n"+pollLink+"\nThank you!", false,
))
if user.SlackUID != "" {
notVotedString = append(notVotedString, "<@"+user.SlackUID+">")
} else {
notVotedString = append(notVotedString, user.Username)
}
Comment on lines +151 to +155

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the SlackUID is empty, I think the the slack message send will error first, and then this won't add the username.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i fixed this? i don't know if I completely understand what you're asking for

if err != nil {
logging.Logger.WithFields(logrus.Fields{"method": "EvaluatePolls dm"}).Error(err)
continue
}
}
// print non-voters to #announcements if we can't close the vote
if !poll.OpenedTime.AddDate(0, 0, 2).After(now) {
_, _, err = slackData.Client.PostMessage(slackData.AnnouncementsChannel,
slack.MsgOptionText("It has been past the default time required to vote on \""+poll.Title+
"\" These people have not completed their responsibility as a Voting Member of House. \n"+
strings.Join(notVotedString, ", "), false))
if err != nil {
logging.Logger.WithFields(logrus.Fields{"method": "EvaluatePolls notVoted announce"}).Error(err)
continue
}
}
continue
}
// close poll after 48 hours
Expand Down
Loading