Skip to content
Open

Dev #56

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
38 changes: 38 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Golang Validation

on:
push:
branches: [master, dev]
pull_request:
branches: [master, dev]

jobs:
golang-checks:
runs-on: ubuntu-latest

strategy:
matrix:
go-version: [1.24]

steps:
- uses: actions/checkout@v2
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Install dependencies
run: |
go mod download
- name: Tidy dependencies
run: |
go mod tidy -diff
- name: Check Format
run: |
gofmt -s -l database logging sse *.go
- name: Run Tests
run: |
go test ./database
- name: Run vet
run: |
go vet ./database/ ./logging/ ./sse/
go vet *.go
21 changes: 21 additions & 0 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: SonarQube

on:
push:
branches:
- dev


jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: SonarSource/sonarqube-scan-action@v6
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ FROM docker.io/golang:1.24-alpine AS build

WORKDIR /src/
RUN apk add git
COPY go* .
COPY *.go .
COPY go.* .
RUN go mod download # do this before build for caching
COPY database database
COPY logging logging
COPY sse sse
COPY *.go .
RUN go build -v -o vote

FROM docker.io/alpine
Expand Down
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Implementation

## Configuration

You'll need to set up these values in your environment. Ask an RTP for OIDC credentials. A docker-compose file is provided for convenience. Otherwise, I trust you to figure it out!
If you're using the compose file, you'll need to ask an RTP for the vote-dev OIDC secret, and set it as `VOTE_OIDC_SECRET` in your environment

If you're not using the compose file, you'll need more of these

```
VOTE_HOST=http://localhost:8080
Expand All @@ -27,10 +29,32 @@ VOTE_SLACK_APP_TOKEN=
VOTE_SLACK_BOT_TOKEN=
```

### Dev Overrides
`DEV_DISABLE_ACTIVE_FILTERS="true"` will disable the requirements that you be active to vote
`DEV_FORCE_IS_EVALS="true"` will force vote to treat all users as the Evals director

## Linting
These will be checked by CI

```
# tidy dependencies
go mod tidy

# format all code according to go standards
gofmt -w -s *.go logging sse database

# run tests (database is the first place we've defined tests)
go test ./database

# run heuristic validation
go vet ./database/ ./logging/ ./sse/
go vet *.go
```

## To-Dos

- [ ] Don't let the user fuck it up
- [ ] Show E-Board polls with a higher priority
- [ ] Move Hide Vote to create instead of after you vote :skull:
- [x] Move Hide Vote to create instead of after you vote :skull:
- [ ] Display the reason why a user is on the results page of a running poll
- [ ] Display minimum time left that a poll is open
8 changes: 7 additions & 1 deletion constitutional.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,14 @@ func EvaluatePolls() {
logging.Logger.WithFields(logrus.Fields{"method": "EvaluatePolls close"}).Error(err)
continue
}
announceStr := "The vote \"" + poll.ShortDescription + "\" has closed."
if !poll.Hidden {
announceStr += " Check out the results at " + pollLink
} else {
announceStr += " Results will be posted shortly."
}
_, _, _, err = slackData.Client.SendMessage(slackData.AnnouncementsChannel,
slack.MsgOptionText("The vote \""+poll.ShortDescription+"\" has closed. Check out the results at "+pollLink, false))
slack.MsgOptionText(announceStr, false))
if err != nil {
logging.Logger.WithFields(logrus.Fields{"method": "EvaluatePolls announce"}).Error(err)
}
Expand Down
9 changes: 8 additions & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"
"strings"
"testing"
"time"

"github.com/computersciencehouse/vote/logging"
Expand All @@ -20,10 +21,16 @@ const (
Updated UpsertResult = 1
)

var Client = Connect()
var Client *mongo.Client = Connect()
var db = ""

func Connect() *mongo.Client {
// This always gets invoked on initialisation. bad! it'd be nice if we only did this setup in main rather than components under test. for now we just skip if testing
if testing.Testing() {
logging.Logger.WithFields(logrus.Fields{"module": "database", "method": "Connect"}).Info("testing, not doing db connection, someone should mock this someday")
return nil
}

logging.Logger.WithFields(logrus.Fields{"module": "database", "method": "Connect"}).Info("beginning database connection")

ctx, cancel := context.WithTimeout(context.TODO(), 10*time.Second)
Expand Down
Loading