Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Format Step in GitHub Workflow #131

Merged
merged 12 commits into from
Feb 1, 2024
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
4 changes: 4 additions & 0 deletions .github/workflows/auto_assign_author.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
types: [opened, ready_for_review, reopened]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
auto-add-assignee:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/auto_request_review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
types: [opened, ready_for_review, reopened]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
auto-request-review:
runs-on: ubuntu-latest
Expand Down
32 changes: 27 additions & 5 deletions .github/workflows/go.yml → .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: Go
name: Backend

on:
push:
branches:
- main
paths:
- "backend/**"
- ".github/workflows/go.yml"
- ".github/workflows/backend.yml"
pull_request:
paths:
- "backend/**"
- ".github/workflows/go.yml"
- ".github/workflows/backend.yml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -27,8 +27,23 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: "1.21"
- name: Enforce formatting
run: gofmt -l ./backend/ | grep ".go$" | xargs -r echo "Files not formatted:"
- name: Cache Go Modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install gofumpt
run: go install mvdan.cc/gofumpt@latest
- name: Check code formatting
run: |
unformatted_files=$(gofumpt -l ./backend/)
if [ -n "$unformatted_files" ]; then
echo "Files not formatted:"
echo "$unformatted_files"
exit 1
fi

lint:
name: Lint
Expand Down Expand Up @@ -68,6 +83,13 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: "1.21"
- name: Cache Go Modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Dependencies
run: cd ./backend/ && go get ./...
- name: Increase max_connections in PostgreSQL
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ on:
schedule:
- cron: "0 0 * * 1"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
analyze-js-ts:
name: Analyze JavaScript and TypeScript
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

<div align="center">
<!-- Github Actions -->
<a href="https://github.com/GenerateNU/sac/actions/workflows/go.yml">
<img src="https://github.com/GenerateNU/sac/actions/workflows/go.yml/badge.svg"
alt="Go Workflow Status" />
<a href="https://github.com/GenerateNU/sac/actions/workflows/backend.yml">
<img src="https://github.com/GenerateNU/sac/actions/workflows/backend.yml/badge.svg"
alt="Backend Workflow Status" />
</a>
</div>

Expand Down
5 changes: 0 additions & 5 deletions backend/src/auth/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ var (

func ComparePasswordAndHash(password, encodedHash string) (bool, error) {
p, salt, hash, err := decodeHash(encodedHash)

if err != nil {
return false, err
}
Expand All @@ -82,7 +81,6 @@ func decodeHash(encodedHash string) (p *params, salt []byte, hash []byte, err er
var version int

_, err = fmt.Sscanf(vals[2], "v=%d", &version)

if err != nil {
return nil, nil, nil, err
}
Expand All @@ -94,21 +92,18 @@ func decodeHash(encodedHash string) (p *params, salt []byte, hash []byte, err er
p = &params{}

_, err = fmt.Sscanf(vals[3], "m=%d,t=%d,p=%d", &p.memory, &p.iterations, &p.parallelism)

if err != nil {
return nil, nil, nil, err
}

salt, err = base64.RawStdEncoding.Strict().DecodeString(vals[4])

if err != nil {
return nil, nil, nil, err
}

p.saltLength = uint32(len(salt))

hash, err = base64.RawStdEncoding.Strict().DecodeString(vals[5])

if err != nil {
return nil, nil, nil, err
}
Expand Down
2 changes: 0 additions & 2 deletions backend/src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const (
)

func GetConfiguration(path string) (Settings, error) {

var environment Environment
if env := os.Getenv("APP_ENVIRONMENT"); env != "" {
environment = Environment(env)
Expand Down Expand Up @@ -117,7 +116,6 @@ func GetConfiguration(path string) (Settings, error) {

portStr := os.Getenv(fmt.Sprintf("%sPORT", appPrefix))
portInt, err := strconv.ParseUint(portStr, 10, 16)

if err != nil {
return Settings{}, fmt.Errorf("failed to parse port: %w", err)
}
Expand Down
2 changes: 0 additions & 2 deletions backend/src/controllers/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func (t *CategoryController) CreateCategory(c *fiber.Ctx) error {
}

newCategory, err := t.categoryService.CreateCategory(categoryBody)

if err != nil {
return err.FiberError(c)
}
Expand Down Expand Up @@ -130,7 +129,6 @@ func (t *CategoryController) UpdateCategory(c *fiber.Ctx) error {
}

updatedCategory, err := t.categoryService.UpdateCategory(c.Params("id"), category)

if err != nil {
return err.FiberError(c)
}
Expand Down
1 change: 0 additions & 1 deletion backend/src/controllers/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func (t *TagController) CreateTag(c *fiber.Ctx) error {
// @Router /api/v1/tags/{id} [get]
func (t *TagController) GetTag(c *fiber.Ctx) error {
tag, err := t.tagService.GetTag(c.Params("categoryID"), c.Params("tagID"))

if err != nil {
return err.FiberError(c)
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/controllers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (u *UserController) GetUserTags(c *fiber.Ctx) error {
return c.Status(fiber.StatusOK).JSON(&tags)
}

func (u *UserController) CreateUserTags(c *fiber.Ctx) error {
func (u *UserController) CreateUserTags(c *fiber.Ctx) error {
var requestBody models.CreateUserTagsBody
if err := c.BodyParser(&requestBody); err != nil {
return errors.FailedToParseRequestBody.FiberError(c)
Expand All @@ -156,6 +156,6 @@ func (u *UserController) CreateUserTags(c *fiber.Ctx) error {
if err != nil {
return err.FiberError(c)
}

return c.Status(fiber.StatusCreated).JSON(&tags)
}
5 changes: 0 additions & 5 deletions backend/src/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ func ConfigureDB(settings config.Settings) (*gorm.DB, error) {
SkipDefaultTransaction: true,
TranslateError: true,
})

if err != nil {
return nil, err
}

err = db.Exec("CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\"").Error

if err != nil {
return nil, err
}
Expand All @@ -36,7 +34,6 @@ func ConfigureDB(settings config.Settings) (*gorm.DB, error) {

func ConnPooling(db *gorm.DB) error {
sqlDB, err := db.DB()

if err != nil {
return err
}
Expand All @@ -58,7 +55,6 @@ func MigrateDB(settings config.Settings, db *gorm.DB) error {
&models.Tag{},
&models.User{},
)

if err != nil {
return err
}
Expand All @@ -82,7 +78,6 @@ func createSuperUser(settings config.Settings, db *gorm.DB) error {
}

passwordHash, err := auth.ComputePasswordHash(settings.SuperUser.Password)

if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/errors/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ var (
StatusCode: fiber.StatusBadRequest,
Message: "failed to validate user",
}
FailedToValidateUserTags = Error {
FailedToValidateUserTags = Error{
StatusCode: fiber.StatusBadRequest,
Message: "failed to validate user tags",
Message: "failed to validate user tags",
}
FailedToCreateUser = Error{
StatusCode: fiber.StatusInternalServerError,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ type UpdateUserRequestBody struct {
}

type CreateUserTagsBody struct {
Tags []uuid.UUID `json:"tags" validate:"required"`
Tags []uuid.UUID `json:"tags" validate:"required"`
}
3 changes: 0 additions & 3 deletions backend/src/services/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ func (c *CategoryService) CreateCategory(categoryBody models.CategoryRequestBody

func (c *CategoryService) GetCategories(limit string, page string) ([]models.Category, *errors.Error) {
limitAsInt, err := utilities.ValidateNonNegative(limit)

if err != nil {
return nil, &errors.FailedToValidateLimit
}

pageAsInt, err := utilities.ValidateNonNegative(page)

if err != nil {
return nil, &errors.FailedToValidatePage
}
Expand All @@ -62,7 +60,6 @@ func (c *CategoryService) GetCategories(limit string, page string) ([]models.Cat

func (c *CategoryService) GetCategory(id string) (*models.Category, *errors.Error) {
idAsUUID, err := utilities.ValidateID(id)

if err != nil {
return nil, err
}
Expand Down
2 changes: 0 additions & 2 deletions backend/src/services/club.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ type ClubService struct {

func (c *ClubService) GetClubs(limit string, page string) ([]models.Club, *errors.Error) {
limitAsInt, err := utilities.ValidateNonNegative(limit)

if err != nil {
return nil, &errors.FailedToValidateLimit
}

pageAsInt, err := utilities.ValidateNonNegative(page)

if err != nil {
return nil, &errors.FailedToValidatePage
}
Expand Down
3 changes: 0 additions & 3 deletions backend/src/services/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ func (u *UserService) CreateUser(userBody models.CreateUserRequestBody) (*models

func (u *UserService) GetUsers(limit string, page string) ([]models.User, *errors.Error) {
limitAsInt, err := utilities.ValidateNonNegative(limit)

if err != nil {
return nil, &errors.FailedToValidateLimit
}

pageAsInt, err := utilities.ValidateNonNegative(page)

if err != nil {
return nil, &errors.FailedToValidatePage
}
Expand Down Expand Up @@ -132,7 +130,6 @@ func (u *UserService) CreateUserTags(id string, tagIDs models.CreateUserTagsBody

// Retrieve a list of valid tags from the ids:
tags, err := transactions.GetTagsByIDs(u.DB, tagIDs.Tags)

if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/transactions/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func GetUserTags(db *gorm.DB, id uuid.UUID) ([]models.Tag, *errors.Error) {
return nil, &errors.UserNotFound
}

if err := db.Model(&user).Association("Tag").Find(&tags) ; err != nil {
if err := db.Model(&user).Association("Tag").Find(&tags); err != nil {
return nil, &errors.FailedToGetTag
}
return tags, nil
Expand Down
1 change: 0 additions & 1 deletion backend/src/utilities/manipulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/mitchellh/mapstructure"
)


// MapRequestToModel maps request data to a target model using mapstructure
func MapRequestToModel[T any, U any](responseData T, targetModel *U) (*U, error) {
config := &mapstructure.DecoderConfig{
Expand Down
1 change: 0 additions & 1 deletion backend/src/utilities/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func validateContactPointer(validate *validator.Validate, fl validator.FieldLeve

func ValidateID(id string) (*uuid.UUID, *errors.Error) {
idAsUUID, err := uuid.Parse(id)

if err != nil {
return nil, &errors.FailedToValidateID
}
Expand Down
6 changes: 3 additions & 3 deletions backend/tests/api/category_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func TestCreateCategoryFailsIfNameIsMissing(t *testing.T) {
func TestCreateCategoryFailsIfCategoryWithThatNameAlreadyExists(t *testing.T) {
existingAppAssert, _ := CreateSampleCategory(t, nil)

var TestNumCategoriesRemainsAt1 = func(app TestApp, assert *assert.A, resp *http.Response) {
TestNumCategoriesRemainsAt1 := func(app TestApp, assert *assert.A, resp *http.Response) {
AssertNumCategoriesRemainsAtN(app, assert, resp, 1)
}

Expand Down Expand Up @@ -295,7 +295,7 @@ func TestUpdateCategoryWorks(t *testing.T) {
"name": "Arts & Crafts",
}

var AssertUpdatedCategoryBodyRespDB = func(app TestApp, assert *assert.A, resp *http.Response) {
AssertUpdatedCategoryBodyRespDB := func(app TestApp, assert *assert.A, resp *http.Response) {
AssertUpdatedCategoryBodyRespDB(app, assert, resp, &category)
}

Expand All @@ -317,7 +317,7 @@ func TestUpdateCategoryWorksWithSameDetails(t *testing.T) {
category := *SampleCategoryFactory()
category["id"] = uuid

var AssertSampleCategoryBodyRespDB = func(app TestApp, assert *assert.A, resp *http.Response) {
AssertSampleCategoryBodyRespDB := func(app TestApp, assert *assert.A, resp *http.Response) {
AssertUpdatedCategoryBodyRespDB(app, assert, resp, &category)
}

Expand Down
2 changes: 0 additions & 2 deletions backend/tests/api/club_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ func TestCreateClubFailsOnInvalidRecruitmentType(t *testing.T) {
"https://google.com",
},
)

}

func TestCreateClubFailsOnInvalidApplicationLink(t *testing.T) {
Expand All @@ -294,7 +293,6 @@ func TestCreateClubFailsOnInvalidApplicationLink(t *testing.T) {
"@#139081#$Ad_Axf",
},
)

}

func TestCreateClubFailsOnInvalidLogo(t *testing.T) {
Expand Down
Loading
Loading