-
Notifications
You must be signed in to change notification settings - Fork 0
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
11 changed files
with
1,097 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/b1zzu/reportportal-dashboards-as-code/pkg/reportportal" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/oauth2" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type Test struct { | ||
Dashboard *reportportal.Dashboard | ||
Widgets []*reportportal.Widget | ||
} | ||
|
||
var ( | ||
exportFile string | ||
exportProject string | ||
exportDashboard int | ||
|
||
exportCmd = &cobra.Command{ | ||
Use: "export", | ||
Short: "Exprt a ReportPortal dashboard to YAML", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
|
||
c := oauth2.NewClient(context.TODO(), oauth2.StaticTokenSource(&oauth2.Token{AccessToken: "TODO"})) | ||
|
||
rp, err := reportportal.NewClient(c, reportportalBaseURL) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
t := &Test{} | ||
|
||
d, _, err := rp.Dashboard.Get(exportProject, exportDashboard) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
t.Dashboard = d | ||
|
||
// retrieve all widgets | ||
ws := make([]*reportportal.Widget, len(d.Widgets)) | ||
for i, w := range d.Widgets { | ||
wr, _, err := rp.Widget.Get(exportProject, w.WidgetId) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ws[i] = wr | ||
} | ||
t.Widgets = ws | ||
|
||
b, err := yaml.Marshal(t) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = os.WriteFile(exportFile, b, 0660) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
exportCmd.Flags().StringVarP(&exportFile, "file", "f", "", "YAML File") | ||
exportCmd.Flags().StringVarP(&exportProject, "project", "p", "", "ReportPortal Project") | ||
exportCmd.Flags().IntVarP(&exportDashboard, "dashboard", "d", -1, "ReportPortal Dashboard ID") | ||
|
||
rootCmd.AddCommand(exportCmd) | ||
} |
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,42 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"github.com/spf13/cobra" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
var ( | ||
importFile string | ||
|
||
importCmd = &cobra.Command{ | ||
Use: "import", | ||
Short: "Import a YAML dashboard to ReportPortal", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
|
||
byteFile, err := ioutil.ReadFile(importFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
data := make(map[interface{}]interface{}) | ||
|
||
err = yaml.Unmarshal(byteFile, data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println(data) | ||
|
||
return nil | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
importCmd.Flags().StringVarP(&importFile, "file", "f", "", "YAML file") | ||
|
||
rootCmd.AddCommand(importCmd) | ||
} |
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,27 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
reportportalBaseURL = "TODO" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "rpdac", | ||
Short: "Import and export ReportPortal dashboards and widget in YAML", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Do Stuff Here | ||
}, | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} |
Empty file.
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,9 @@ | ||
module github.com/b1zzu/reportportal-dashboards-as-code | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/spf13/cobra v1.2.1 | ||
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
) |
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,7 @@ | ||
package main | ||
|
||
import "github.com/b1zzu/reportportal-dashboards-as-code/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
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,51 @@ | ||
package reportportal | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type DashboardService service | ||
|
||
type Dashboard struct { | ||
Owner string `json:"owner"` | ||
Share bool `json:"share"` | ||
ID int `json:"id"` | ||
Name string `json:"name"` | ||
Widgets []*DashboardWidget `json:"widgets"` | ||
} | ||
|
||
type DashboardWidget struct { | ||
WidgetName string `json:"widgetName"` | ||
WidgetId int `json:"widgetId"` | ||
WidgetType string `json:"widgetType"` | ||
WidgetSize *DashboardWidgetSize `json:"widgetSize"` | ||
WidgetPosition *DashboardWidgetPosition `json:"widgetPosition"` | ||
Share bool `json:"share"` | ||
} | ||
|
||
type DashboardWidgetSize struct { | ||
Width int `json:"width"` | ||
Height int `json:"height"` | ||
} | ||
|
||
type DashboardWidgetPosition struct { | ||
PositionX int `json:"positionX"` | ||
PositionY int `json:"positionY"` | ||
} | ||
|
||
func (s *DashboardService) Get(projectName string, id int) (*Dashboard, *Response, error) { | ||
u := fmt.Sprintf("v1/%v/dashboard/%v", projectName, id) | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
d := new(Dashboard) | ||
resp, err := s.client.Do(req, d) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return d, resp, nil | ||
} |
Oops, something went wrong.