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

fix: sheet enrichment #319

Merged
merged 3 commits into from
Jan 9, 2025
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
2 changes: 1 addition & 1 deletion core/scheduler/service/deployment_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func TestDeploymentService(t *testing.T) {
defer mScheduler.AssertExpectations(t)

runService := service.NewJobRunService(logger, jobRepo, nil, nil, nil,
mScheduler, priorityResolver, nil, nil, nil, nil)
mScheduler, priorityResolver, nil, nil, nil)

err := runService.UploadJobs(ctx, tnnt1, jobNamesToUpload, jobNamesToDelete)
assert.ErrorContains(t, err, upstreamErr)
Expand Down
17 changes: 12 additions & 5 deletions ext/sheets/gsheet/gsheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,28 @@ func (gs *GSheets) getSheetContent(sheetID, sheetRange string) ([][]interface{},
return nil, errors.New("no sheets found in the spreadsheet ")
}

if len(resp.ValueRanges[0].Values) == 0 {
return nil, errors.New("no data found in the sheet[0]")
}
return resp.ValueRanges[0].Values, nil
}

func (gs *GSheets) GetSheetName(sheetID string) (string, error) {
spreadsheet, err := gs.srv.Spreadsheets.Get(sheetID).Do()
func (gs *GSheets) GetSheetName(sheetURL string) (string, error) {
sheetInfo, err := FromURL(sheetURL)
if err != nil {
return "", err
}
spreadsheet, err := gs.srv.Spreadsheets.Get(sheetInfo.SheetID).Do()
if err != nil {
return "", err
}

if len(spreadsheet.Sheets) == 0 {
return "", errors.New("no sub sheet found")
}

for _, s := range spreadsheet.Sheets {
if s.Properties.SheetId == sheetInfo.GID {
return s.Properties.Title, nil
}
}
sid := spreadsheet.Sheets[0].Properties.Title
return sid, err
}
10 changes: 7 additions & 3 deletions ext/sheets/gsheet/sheet_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gsheet
import (
"errors"
"regexp"
"strconv"
)

var (
Expand All @@ -12,7 +13,7 @@ var (

type SheetsInfo struct {
SheetID string
GID string
GID int64
}

func FromURL(u1 string) (*SheetsInfo, error) {
Expand All @@ -21,10 +22,13 @@ func FromURL(u1 string) (*SheetsInfo, error) {
return nil, errors.New("not able to get spreadsheetID")
}

gid := ""
gid := int64(-1)
res2 := gidRegex.FindStringSubmatch(u1)
if len(res2) > 1 && res2[1] != "" {
gid = res2[1]
gid1, err := strconv.ParseInt(res2[1], 10, 64)
if err == nil {
gid = gid1
}
}

return &SheetsInfo{
Expand Down
8 changes: 4 additions & 4 deletions ext/sheets/gsheet/sheet_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ func TestSheetInfo(t *testing.T) {

info, err := gsheet.FromURL(u1)
assert.Nil(t, err)
assert.Equal(t, info.SheetID, "abcedefgh")
assert.Equal(t, info.GID, "")
assert.Equal(t, "abcedefgh", info.SheetID)
assert.Equal(t, int64(-1), info.GID)
})
t.Run("return sheet info with sid and gid", func(t *testing.T) {
u1 := "https://docs.google.com/spreadsheets/d/abcdeghi/edit#gid=3726"

info, err := gsheet.FromURL(u1)
assert.Nil(t, err)
assert.Equal(t, info.SheetID, "abcdeghi")
assert.Equal(t, info.GID, "3726")
assert.Equal(t, "abcdeghi", info.SheetID)
assert.Equal(t, int64(3726), info.GID)
})
}
Loading