-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1,103 changed files
with
443,668 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module github.com/feloy/junit-collector | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/joshdk/go-junit v1.0.0 | ||
golang.org/x/oauth2 v0.8.0 | ||
google.golang.org/api v0.125.0 | ||
) | ||
|
||
require ( | ||
cloud.google.com/go/compute v1.19.3 // indirect | ||
cloud.google.com/go/compute/metadata v0.2.3 // indirect | ||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/google/s2a-go v0.1.4 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect | ||
github.com/googleapis/gax-go/v2 v2.10.0 // indirect | ||
go.opencensus.io v0.24.0 // indirect | ||
golang.org/x/crypto v0.9.0 // indirect | ||
golang.org/x/net v0.10.0 // indirect | ||
golang.org/x/sys v0.8.0 // indirect | ||
golang.org/x/text v0.9.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect | ||
google.golang.org/grpc v1.55.0 // indirect | ||
google.golang.org/protobuf v1.30.0 // indirect | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/feloy/junit-collector/pkg/db" | ||
"github.com/joshdk/go-junit" | ||
) | ||
|
||
func usage(msg string) { | ||
fmt.Printf("%s\n\nUsage: %s --sheetId <spreadsheetId> --junit <junit-file> --pr <pr-number> --test <test title> --logfile <logfile>\n", msg, os.Args[0]) | ||
os.Exit(1) | ||
} | ||
|
||
/* | ||
GOOGLE_APPLICATION_CREDENTIALS must point to an existing GCP JSON Service account file. | ||
The service account does not need any extra role. | ||
The service account must have an Editor access to the Sheet (use the Share button on the Sheet UI to add this permission) | ||
*/ | ||
func main() { | ||
var ( | ||
fSheetId = flag.String("sheetId", "", "spreadsheetId") | ||
fJunitFile = flag.String("junit", "", "junit file") | ||
fPrNumber = flag.String("pr", "", "PR number") | ||
fTestTile = flag.String("test", "", "Test title") | ||
fLogFile = flag.String("logfile", "", "Log file including base") | ||
) | ||
|
||
flag.Parse() | ||
|
||
if *fSheetId == "" { | ||
usage("--sheetId is missing") | ||
} | ||
spreadsheetId := *fSheetId | ||
|
||
if *fJunitFile == "" { | ||
usage("--junit is missing") | ||
} | ||
junitFile := *fJunitFile | ||
|
||
if *fPrNumber == "" { | ||
usage("--pr is missing") | ||
} | ||
prNumber := *fPrNumber | ||
|
||
if *fTestTile == "" { | ||
usage("--test is missing") | ||
} | ||
testTitle := *fTestTile | ||
|
||
if *fLogFile == "" { | ||
usage("--logfile is missing") | ||
} | ||
logFile := *fLogFile | ||
|
||
ctx := context.Background() | ||
|
||
oldDate := time.Now().Add(-15 * 24 * time.Hour) | ||
fmt.Printf("Deleting entries before: %s\n", oldDate.Format("2006-01-02")) | ||
err := db.Clean(ctx, spreadsheetId, oldDate.Format("2006-01-02")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
suites, err := junit.IngestFile(junitFile) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
for _, suite := range suites { | ||
for _, test := range suite.Tests { | ||
if test.Error == nil { | ||
continue | ||
} | ||
currentTime := time.Now() | ||
data := []interface{}{ | ||
// Date must be set in this format, to be correctly comparable as strings | ||
currentTime.Format("2006-01-02"), | ||
test.Name, | ||
test.Error.Error(), | ||
prNumber, | ||
testTitle, | ||
logFile, | ||
} | ||
err = db.SaveToSheet(ctx, spreadsheetId, data) | ||
if err != nil { | ||
log.Fatalf("Unable to add data to sheet: %v", err) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"google.golang.org/api/sheets/v4" | ||
) | ||
|
||
func Clean(ctx context.Context, sheetId string, beforeDate string) error { | ||
srv, err := getService(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
range_ := "Template!A2:A" | ||
|
||
result, err := srv.Spreadsheets.Values.Get(sheetId, range_).Do() | ||
if err != nil { | ||
return err | ||
} | ||
var rowNumber int64 = 2 | ||
for _, row := range result.Values { | ||
value := row[0].(string) | ||
if value >= beforeDate { | ||
if rowNumber > 2 { | ||
fmt.Printf("Delete rows from 2 to %d\n", rowNumber-1) | ||
} | ||
break | ||
} | ||
rowNumber++ | ||
} | ||
|
||
if rowNumber < 3 { | ||
return nil | ||
} | ||
|
||
var requests []*sheets.Request | ||
requests = append(requests, &sheets.Request{ | ||
DeleteDimension: &sheets.DeleteDimensionRequest{ | ||
Range: &sheets.DimensionRange{ | ||
Dimension: "ROWS", | ||
StartIndex: 1, // 0-index, inclusive | ||
EndIndex: rowNumber - 1, // 0-index, exclusive | ||
}, | ||
}, | ||
}) | ||
req := sheets.BatchUpdateSpreadsheetRequest{ | ||
Requests: requests, | ||
} | ||
_, err = srv.Spreadsheets.BatchUpdate(sheetId, &req).Do() | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
|
||
"golang.org/x/oauth2/google" | ||
"google.golang.org/api/option" | ||
"google.golang.org/api/sheets/v4" | ||
) | ||
|
||
func getService(ctx context.Context) (*sheets.Service, error) { | ||
client, err := google.DefaultClient(ctx, "https://www.googleapis.com/auth/spreadsheets") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
srv, err := sheets.NewService(ctx, option.WithHTTPClient(client)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return srv, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
|
||
"google.golang.org/api/sheets/v4" | ||
) | ||
|
||
func SaveToSheet(ctx context.Context, sheetId string, data []interface{}) error { | ||
srv, err := getService(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
readRange := "Template" | ||
valueRange := sheets.ValueRange{ | ||
MajorDimension: "ROWS", | ||
Range: "Template", | ||
Values: [][]interface{}{ | ||
data, | ||
}, | ||
} | ||
_, err = srv.Spreadsheets.Values. | ||
Append(sheetId, readRange, &valueRange). | ||
ValueInputOption("USER_ENTERED").Do() | ||
return err | ||
} |
Oops, something went wrong.