Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions src/results.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This module defines the logic to calculate vote results.

use std::{collections::HashMap, fmt};
use std::{collections::BTreeMap, fmt};

use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -113,7 +113,7 @@ pub(crate) struct VoteResults {
pub binding: i64,
pub non_binding: i64,
pub allowed_voters: i64,
pub votes: HashMap<UserName, UserVote>,
pub votes: BTreeMap<UserName, UserVote>,
pub pending_voters: Vec<UserName>,
}

Expand Down Expand Up @@ -141,7 +141,7 @@ pub(crate) async fn calculate<'a>(
gh.get_allowed_voters(inst_id, &vote.cfg, owner, repo, vote.organization.as_ref()).await?;

// Track users votes
let mut votes: HashMap<UserName, UserVote> = HashMap::new();
let mut votes: BTreeMap<UserName, UserVote> = BTreeMap::new();
let mut multiple_options_voters: Vec<UserName> = Vec::new();
for reaction in reactions {
// Get vote option from reaction
Expand Down Expand Up @@ -345,7 +345,7 @@ mod tests {
not_voted: 0,
binding: 1,
non_binding: 0,
votes: HashMap::from([
votes: BTreeMap::from([
(
USER1.to_string(),
UserVote {
Expand Down Expand Up @@ -393,7 +393,7 @@ mod tests {
not_voted: 1,
binding: 0,
non_binding: 0,
votes: HashMap::new(),
votes: BTreeMap::new(),
allowed_voters: 1,
pending_voters: vec![USER1.to_string()],
}
Expand Down Expand Up @@ -445,7 +445,7 @@ mod tests {
not_voted: 1,
binding: 3,
non_binding: 1,
votes: HashMap::from([
votes: BTreeMap::from([
(
USER1.to_string(),
UserVote {
Expand Down Expand Up @@ -525,7 +525,7 @@ mod tests {
not_voted: 1,
binding: 3,
non_binding: 0,
votes: HashMap::from([
votes: BTreeMap::from([
(
USER1.to_string(),
UserVote {
Expand Down
1 change: 1 addition & 0 deletions src/testdata/templates/config-not-found.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Configuration file not found. Please see <https://github.com/cncf/gitvote#configuration>.
1 change: 1 addition & 0 deletions src/testdata/templates/config-profile-not-found.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The requested configuration profile was not found in the configuration file.
5 changes: 5 additions & 0 deletions src/testdata/templates/invalid-config.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Something went wrong while processing the configuration file:

```text
Missing required field: pass_threshold
```
1 change: 1 addition & 0 deletions src/testdata/templates/no-vote-in-progress-issue.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
There is no vote in progress to cancel in this issue @testuser.
1 change: 1 addition & 0 deletions src/testdata/templates/no-vote-in-progress-pr.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
There is no vote in progress to cancel in this pull request @testuser.
3 changes: 3 additions & 0 deletions src/testdata/templates/vote-cancelled-issue.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Vote cancelled

@testuser has cancelled the vote in progress in this issue.
3 changes: 3 additions & 0 deletions src/testdata/templates/vote-cancelled-pr.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Vote cancelled

@testuser has cancelled the vote in progress in this pull request.
1 change: 1 addition & 0 deletions src/testdata/templates/vote-checked-recently.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Votes can only be checked once a day.
22 changes: 22 additions & 0 deletions src/testdata/templates/vote-closed-announcement.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The vote for "**Implement RFC-42** (**#123**)" is now closed.

## Vote results

The vote **passed**! 🎉

`66.67%` of the users with binding vote were in favor and `0.00%` were against (passing threshold: `50%`).

### Summary

| In favor | Against | Abstain | Not voted |
| :--------------------: | :-------------------: | :------------------: | :---------------------: |
| 2 | 0 | 1 | 0 |

### Binding votes (3)

| User | Vote | Timestamp |
| ---- | :---: | :-------: |
| @alice | In favor | 2023-01-04 10:00:00.0 +00:00:00 |
| @bob | In favor | 2023-01-04 11:00:00.0 +00:00:00 |
| @charlie | Abstain | 2023-01-04 12:00:00.0 +00:00:00 |

22 changes: 22 additions & 0 deletions src/testdata/templates/vote-closed-failed.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Vote closed

The vote **did not pass**.

`40.00%` of the users with binding vote were in favor and `60.00%` were against (passing threshold: `50%`).

### Summary

| In favor | Against | Abstain | Not voted |
| :--------------------: | :-------------------: | :------------------: | :---------------------: |
| 2 | 3 | 0 | 0 |

### Binding votes (5)

| User | Vote | Timestamp |
| ---- | :---: | :-------: |
| @alice | Against | 2023-01-02 10:00:00.0 +00:00:00 |
| @bob | In favor | 2023-01-02 11:00:00.0 +00:00:00 |
| @charlie | Against | 2023-01-02 12:00:00.0 +00:00:00 |
| @dave | In favor | 2023-01-02 13:00:00.0 +00:00:00 |
| @eve | Against | 2023-01-02 14:00:00.0 +00:00:00 |

31 changes: 31 additions & 0 deletions src/testdata/templates/vote-closed-passed.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Vote closed

The vote **passed**! 🎉

`80.00%` of the users with binding vote were in favor and `20.00%` were against (passing threshold: `50%`).

### Summary

| In favor | Against | Abstain | Not voted |
| :--------------------: | :-------------------: | :------------------: | :---------------------: |
| 4 | 1 | 0 | 0 |

### Binding votes (5)

| User | Vote | Timestamp |
| ---- | :---: | :-------: |
| @alice | In favor | 2023-01-01 10:00:00.0 +00:00:00 |
| @bob | In favor | 2023-01-01 11:00:00.0 +00:00:00 |
| @charlie | Against | 2023-01-01 12:00:00.0 +00:00:00 |
| @dave | In favor | 2023-01-01 13:00:00.0 +00:00:00 |
| @eve | In favor | 2023-01-01 14:00:00.0 +00:00:00 |

<details>
<summary><h3>Non-binding votes (2)</h3></summary>

| User | Vote | Timestamp |
| ---- | :---: | :-------: |
| @supporter1 | In favor | 2023-01-01 15:00:00.0 +00:00:00 |
| @supporter2 | In favor | 2023-01-01 16:00:00.0 +00:00:00 |
</details>

19 changes: 19 additions & 0 deletions src/testdata/templates/vote-created-all-collaborators.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Vote created

**@user** has called for a vote on `Test title` (#1).

All repository collaborators have binding votes.

Non-binding votes are also appreciated as a sign of support!

## How to vote

You can cast your vote by reacting to `this` comment. The following reactions are supported:

| In favor | Against | Abstain |
| :------: | :-----: | :-----: |
| 👍 | 👎 | 👀 |

*Please note that voting for multiple options is not allowed and those votes won't be counted.*

The vote will be open for `1day`. It will pass if at least `75%` of the users with binding votes vote `In favor 👍`. Once it's closed, results will be published here as a new comment.
29 changes: 29 additions & 0 deletions src/testdata/templates/vote-created-with-teams-and-users.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Vote created

**@user** has called for a vote on `Add new feature X` (#42).

The members of the following teams have binding votes:
| Team |
| ---- |
| @org/core-team |
| @org/maintainers |

The following users have binding votes:
| User |
| ---- |
| @alice |
| @bob |

Non-binding votes are also appreciated as a sign of support!

## How to vote

You can cast your vote by reacting to `this` comment. The following reactions are supported:

| In favor | Against | Abstain |
| :------: | :-----: | :-----: |
| 👍 | 👎 | 👀 |

*Please note that voting for multiple options is not allowed and those votes won't be counted.*

The vote will be open for `3days`. It will pass if at least `51%` of the users with binding votes vote `In favor 👍`. Once it's closed, results will be published here as a new comment.
3 changes: 3 additions & 0 deletions src/testdata/templates/vote-in-progress-issue.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
There is already a vote in progress in this issue @testuser.

Please wait until it is closed before creating a new one.
3 changes: 3 additions & 0 deletions src/testdata/templates/vote-in-progress-pr.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
There is already a vote in progress in this pull request @testuser.

Please wait until it is closed before creating a new one.
3 changes: 3 additions & 0 deletions src/testdata/templates/vote-restricted.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Only repository collaborators can create a vote @testuser.

For organization-owned repositories, the list of collaborators includes outside collaborators, organization members that are direct collaborators, organization members with access through team memberships, organization members with access through default organization permissions, and organization owners.
25 changes: 25 additions & 0 deletions src/testdata/templates/vote-status-in-progress.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Vote status

So far `33.33%` of the users with binding vote are in favor and `0.00%` are against (passing threshold: `50%`).

### Summary

| In favor | Against | Abstain | Not voted |
| :--------------------: | :-------------------: | :------------------: | :---------------------: |
| 1 | 0 | 1 | 1 |

### Binding votes (2)

| User | Vote | Timestamp |
| ---- | :---: | :-------: |
| alice | In favor | 2023-01-03 10:00:00.0 +00:00:00 |
| bob | Abstain | 2023-01-03 11:00:00.0 +00:00:00 |
| @charlie | *Pending* | |

<details>
<summary><h3>Non-binding votes (1)</h3></summary>

| User | Vote | Timestamp |
| ---- | :---: | :-------: |
| supporter | In favor | 2023-01-03 12:00:00.0 +00:00:00 |
</details>
4 changes: 2 additions & 2 deletions src/testutil.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This modules defines some test utilities.

use std::{collections::HashMap, fs, path::Path, time::Duration};
use std::{collections::BTreeMap, fs, path::Path, time::Duration};

use time::{format_description::well_known::Rfc3339, OffsetDateTime};
use uuid::Uuid;
Expand Down Expand Up @@ -166,7 +166,7 @@ pub(crate) fn setup_test_vote_results() -> VoteResults {
not_voted: 0,
binding: 1,
non_binding: 0,
votes: HashMap::from([(
votes: BTreeMap::from([(
USER1.to_string(),
UserVote {
vote_option: VoteOption::InFavor,
Expand Down
Loading