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
18 changes: 11 additions & 7 deletions .junie/guidelines.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

## Global rules
- You must always ask before creating mocks

## SQLC queries
## SQLite queries

When writing SQL queries ensure you annotate your queries

following are examples of correct annotations
- When writing sqlite queries use the tool [sqlc](https://sqlc.dev/)
- When writing SQL queries ensure you annotate your queries
- Following are examples of correct annotations
- after you finished writing the queries, use the command `task gen` to generate the boilerplate go code

```sql
-- name: GetAuthor :one
Expand Down Expand Up @@ -80,10 +83,12 @@ review `taskfile.yaml` for list of commands available in repo.

### Testing:
- Write **unit tests** using use [odize](https://github.com/code-gorilla-au/odize) as the test framework and parallel execution.
- Do not mock out the database, we're using sqlite and embedded db for tests.
- Think about edge cases, within reason.
- **Mock external interfaces** cleanly using generated ([Moq](https://github.com/matryer/moq)) or handwritten mocks.
- Separate **fast unit tests** from slower integration and E2E tests.
- Ensure **test coverage** for every exported function, with behavioural checks.
- Test coverage command is: `task go-cover`.
- Test command with coverage is: `task go-cover`.


#### Example odize framework
Expand Down Expand Up @@ -114,8 +119,7 @@ func TestQueries(t *testing.T) {
"owner",
"login",
}))

// Interpolated parameters

odize.AssertTrue(t, containsAll(q, []string{
"owner:" + owner,
"topic:" + topic,
Expand Down
34 changes: 34 additions & 0 deletions cmd/local/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"context"
"os"
"watchtower/internal/database"
"watchtower/internal/logging"
"watchtower/internal/watchtower"
)

func main() {

appConfig := watchtower.LoadConfig()
logger := logging.FromContext(context.Background()).With("service", "local")

_, db, err := database.NewDBFromProvider(appConfig.AppDir)
if err != nil {
logger.Error("Error creating database", "error", err)
os.Exit(1)
}

defer func() {
if err = db.Close(); err != nil {
logger.Error("Error closing database", "error", err)
}
}()

migrator := database.NewMigrator(db)

if err = migrator.Init(); err != nil {
logger.Error("Error running migrations", "error", err)
os.Exit(1)
}
}
8 changes: 6 additions & 2 deletions frontend/src/lib/wailsjs/go/watchtower/Service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export function CreateOrganisation(arg1:string,arg2:string,arg3:string,arg4:stri

export function CreateProduct(arg1:string,arg2:string,arg3:Array<string>,arg4:number):Promise<products.ProductDTO>;

export function CreateUnreadPRNotification():Promise<void>;

export function CreateUnreadSecurityNotification():Promise<void>;

export function DeleteAllOrgs():Promise<void>;

export function DeleteOldNotifications():Promise<void>;
Expand Down Expand Up @@ -37,7 +41,7 @@ export function GetSecurityByOrganisation(arg1:number):Promise<Array<products.Se

export function GetSecurityByProductID(arg1:number):Promise<Array<products.SecurityDTO>>;

export function GetUnreadNotifications(arg1:number):Promise<Array<notifications.Notification>>;
export function GetUnreadNotifications():Promise<Array<notifications.Notification>>;

export function MarkNotificationAsRead(arg1:number):Promise<void>;

Expand All @@ -53,4 +57,4 @@ export function SyncProduct(arg1:number):Promise<void>;

export function UpdateOrganisation(arg1:organisations.UpdateOrgParams):Promise<organisations.OrganisationDTO>;

export function UpdateProduct(arg1:number,arg2:string,arg3:Array<string>):Promise<products.ProductDTO>;
export function UpdateProduct(arg1:number,arg2:string,arg3:string,arg4:Array<string>):Promise<products.ProductDTO>;
16 changes: 12 additions & 4 deletions frontend/src/lib/wailsjs/go/watchtower/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export function CreateProduct(arg1, arg2, arg3, arg4) {
return window['go']['watchtower']['Service']['CreateProduct'](arg1, arg2, arg3, arg4);
}

export function CreateUnreadPRNotification() {
return window['go']['watchtower']['Service']['CreateUnreadPRNotification']();
}

export function CreateUnreadSecurityNotification() {
return window['go']['watchtower']['Service']['CreateUnreadSecurityNotification']();
}

export function DeleteAllOrgs() {
return window['go']['watchtower']['Service']['DeleteAllOrgs']();
}
Expand Down Expand Up @@ -66,8 +74,8 @@ export function GetSecurityByProductID(arg1) {
return window['go']['watchtower']['Service']['GetSecurityByProductID'](arg1);
}

export function GetUnreadNotifications(arg1) {
return window['go']['watchtower']['Service']['GetUnreadNotifications'](arg1);
export function GetUnreadNotifications() {
return window['go']['watchtower']['Service']['GetUnreadNotifications']();
}

export function MarkNotificationAsRead(arg1) {
Expand Down Expand Up @@ -98,6 +106,6 @@ export function UpdateOrganisation(arg1) {
return window['go']['watchtower']['Service']['UpdateOrganisation'](arg1);
}

export function UpdateProduct(arg1, arg2, arg3) {
return window['go']['watchtower']['Service']['UpdateProduct'](arg1, arg2, arg3);
export function UpdateProduct(arg1, arg2, arg3, arg4) {
return window['go']['watchtower']['Service']['UpdateProduct'](arg1, arg2, arg3, arg4);
}
4 changes: 2 additions & 2 deletions frontend/src/lib/watchtower/products.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export class ProductsService {
return product;
}

async update(id: number, name: string, tags: string[]) {
const product = await UpdateProduct(id, name, tags);
async update(id: number, name: string, description: string, tags: string[]) {
const product = await UpdateProduct(id, name, description, tags);
this.internalUpdateProduct(product);

return product;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
try {
pageState.loading = true;
pageState.error = undefined;
await productSvc.update(product.id, formData.name, formData.tags.split(","));
await productSvc.update(
product.id,
formData.name,
formData.description,
formData.tags.split(",")
);
} catch (e) {
const err = e as Error;
pageState.error = err.message;
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/code-gorilla-au/fetch v1.1.0
github.com/code-gorilla-au/odize v1.3.4
github.com/go-co-op/gocron/v2 v2.19.0
github.com/google/uuid v1.6.0
github.com/wailsapp/wails/v2 v2.11.0
modernc.org/sqlite v1.42.2
)
Expand All @@ -16,7 +17,6 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
github.com/joho/godotenv v1.5.1 // indirect
Expand Down
5 changes: 5 additions & 0 deletions internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
_ "embed"
"path"
"strings"

_ "modernc.org/sqlite"
)
Expand Down Expand Up @@ -47,3 +48,7 @@ func resolveDBPath(filePath string) string {

return path.Join(filePath, dbName, "?_busy_timeout=5000")
}

func IsErrUniqueConstraint(err error) bool {
return err != nil && strings.Contains(err.Error(), "constraint failed: UNIQUE constraint failed")
}
1 change: 1 addition & 0 deletions internal/database/models.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 45 additions & 7 deletions internal/database/notifications.sql.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading