Skip to content

Commit

Permalink
Merge pull request #5 from toshi0383/ts-cleanup
Browse files Browse the repository at this point in the history
refactor: filed -> field
  • Loading branch information
shuntaka9576 authored Jun 1, 2023
2 parents d2d7a97 + a75d3cd commit 286f8db
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions gh/p2_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion gh/p2_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand Down
2 changes: 1 addition & 1 deletion gh/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions p2_fileds.go → p2_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -28,8 +28,8 @@ type GetProjectFiledsGhRes struct {
} `json:"data"`
}

type GetProjectFiledsRes struct {
Fileds []Filed
type GetProjectFieldsRes struct {
Fields []Filed
}

type Filed struct {
Expand All @@ -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,
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions p2_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type CreateIssueParams struct {
Body string
Draft bool
Repo string
Fileds []CreateFiled
Fields []CreateFiled
Assignees []string
Labels []string
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 286f8db

Please sign in to comment.