From a75d3cd9404d3f063b9858ab3cf81d2fb8d60771 Mon Sep 17 00:00:00 2001 From: toshi0383 Date: Wed, 31 May 2023 20:44:49 +0900 Subject: [PATCH] refactor: filed -> field --- cli/create.go | 12 ++++++------ gh/p2_fields.go | 4 ++-- gh/p2_list.go | 2 +- gh/query.go | 2 +- p2_fileds.go => p2_fields.go | 20 ++++++++++---------- p2_issue.go | 12 ++++++------ 6 files changed, 26 insertions(+), 26 deletions(-) rename p2_fileds.go => p2_fields.go (74%) diff --git a/cli/create.go b/cli/create.go index c80352b..766cbb1 100644 --- a/cli/create.go +++ b/cli/create.go @@ -33,25 +33,25 @@ func (c *Cmd) Create(params *CreateParamas) error { } // get project status item - projectFileds, err := c.Client.GetProjectFields(&ghp2.GetProjectFieldsParams{ + projectFields, err := c.Client.GetProjectFields(&ghp2.GetProjectFieldsParams{ ProjectId: params.ProjectId, }) if err != nil { return fmt.Errorf("exec create error: %s", err) } - updateFileds := []ghp2.CreateFiled{} + updateFields := []ghp2.CreateFiled{} for _, updateFiled := range params.Fields { updateFiledName := strings.Split(updateFiled, ":")[0] updateFiledValue := strings.Split(updateFiled, ":")[1] - for _, filed := range projectFileds.Fileds { + for _, filed := range projectFields.Fields { if updateFiledName == filed.Name { // TODO ghp2.ITERATION if filed.DataType == gh.SINGLE_SELECT { for _, option := range filed.Options { if updateFiledValue == option.Name { - updateFileds = append(updateFileds, ghp2.CreateFiled{ + updateFields = append(updateFields, ghp2.CreateFiled{ Id: filed.Id, Name: filed.Name, DataType: filed.DataType, @@ -60,7 +60,7 @@ func (c *Cmd) Create(params *CreateParamas) error { } } } else { - updateFileds = append(updateFileds, ghp2.CreateFiled{ + updateFields = append(updateFields, ghp2.CreateFiled{ Id: filed.Id, Name: filed.Name, DataType: filed.DataType, @@ -76,7 +76,7 @@ func (c *Cmd) Create(params *CreateParamas) error { Title: params.Title, Body: params.Body, Draft: params.Draft, - Fileds: updateFileds, + Fields: updateFields, Repo: params.Repo, Assignees: params.Assignees, Labels: params.Labels, diff --git a/gh/p2_fields.go b/gh/p2_fields.go index aca1528..a463a41 100644 --- a/gh/p2_fields.go +++ b/gh/p2_fields.go @@ -4,11 +4,11 @@ import ( "github.com/cli/go-gh" ) -type GetProjectFiledsParams struct { +type GetProjectFieldsParams struct { ProjectId string } -func GetProjectFields(params *GetProjectFiledsParams) (*[]byte, error) { +func GetProjectFields(params *GetProjectFieldsParams) (*[]byte, error) { ghql := "query=" + GetProjectFieldsQuery(params.ProjectId) args := append(graphqlArgs, ghql) diff --git a/gh/p2_list.go b/gh/p2_list.go index 7af9974..5c37210 100644 --- a/gh/p2_list.go +++ b/gh/p2_list.go @@ -8,7 +8,7 @@ type ListProjectParams struct { } func ListProject(params *ListProjectParams) (*[]byte, error) { - ghql := "query=" + GenListQuery(params.ClientType, params.Name) + ghql := "query=" + GetListQuery(params.ClientType, params.Name) args := append(graphqlArgs, ghql) stdOut, _, err := gh.Exec(args...) diff --git a/gh/query.go b/gh/query.go index 6512943..337459a 100644 --- a/gh/query.go +++ b/gh/query.go @@ -22,7 +22,7 @@ func GetUserQuery(users []string) string { return query } -func GenListQuery(clientType ClientType, name string) string { +func GetListQuery(clientType ClientType, name string) string { query := fmt.Sprintf(`query{ %s(login: "%s") { projectsV2(first: 20) { diff --git a/p2_fileds.go b/p2_fields.go similarity index 74% rename from p2_fileds.go rename to p2_fields.go index efc8176..309af8f 100644 --- a/p2_fileds.go +++ b/p2_fields.go @@ -10,10 +10,10 @@ type GetProjectFieldsParams struct { ProjectId string } -type GetProjectFiledsGhRes struct { +type GetProjectFieldsGhRes struct { Data struct { Node struct { - Fileds struct { + Fields struct { Nodes []struct { Id string `json:"id"` Name string `json:"name"` @@ -28,8 +28,8 @@ type GetProjectFiledsGhRes struct { } `json:"data"` } -type GetProjectFiledsRes struct { - Fileds []Filed +type GetProjectFieldsRes struct { + Fields []Filed } type Filed struct { @@ -42,23 +42,23 @@ type Filed struct { } } -func (c *Client) GetProjectFields(params *GetProjectFieldsParams) (*GetProjectFiledsRes, error) { - payload, err := gh.GetProjectFields(&gh.GetProjectFiledsParams{ +func (c *Client) GetProjectFields(params *GetProjectFieldsParams) (*GetProjectFieldsRes, error) { + payload, err := gh.GetProjectFields(&gh.GetProjectFieldsParams{ ProjectId: params.ProjectId, }) if err != nil { return nil, err } - parsed := &GetProjectFiledsGhRes{} + parsed := &GetProjectFieldsGhRes{} err = json.Unmarshal(*payload, parsed) if err != nil { return nil, err } - res := &GetProjectFiledsRes{} + res := &GetProjectFieldsRes{} - for _, node := range parsed.Data.Node.Fileds.Nodes { + for _, node := range parsed.Data.Node.Fields.Nodes { filed := Filed{ Id: node.Id, DataType: node.DataType, @@ -72,7 +72,7 @@ func (c *Client) GetProjectFields(params *GetProjectFieldsParams) (*GetProjectFi }(node.Options) } - res.Fileds = append(res.Fileds, filed) + res.Fields = append(res.Fields, filed) } return res, nil diff --git a/p2_issue.go b/p2_issue.go index 5a5e5fb..5d93ce9 100644 --- a/p2_issue.go +++ b/p2_issue.go @@ -14,7 +14,7 @@ type CreateIssueParams struct { Body string Draft bool Repo string - Fileds []CreateFiled + Fields []CreateFiled Assignees []string Labels []string } @@ -147,14 +147,14 @@ func (c *Client) CreateIssue(params *CreateIssueParams) (err error) { itemId = addItemRes.Data.AddProjectV2ItemById.Item.Id } - // project item apply fileds - for _, filed := range params.Fileds { + // project item apply fields + for _, field := range params.Fields { _, err := gh.UpdateItem(&gh.UpdateItemParams{ ProjectId: params.ProjectId, ItemId: itemId, - FieldId: filed.Id, - ValueType: filed.DataType, - Value: filed.Value, + FieldId: field.Id, + ValueType: field.DataType, + Value: field.Value, }) if err != nil { return err