From 612f8e996051ed63c6122ef1f9833f5e3dde38bc Mon Sep 17 00:00:00 2001 From: 030 Date: Wed, 18 Aug 2021 07:01:42 +0200 Subject: [PATCH] [GH-1] Create a Jira issue. --- CHANGELOG.md | 13 ++++- cmd/jops/create.go | 54 +++++++++++++++++++ cmd/jops/done.go | 17 +----- cmd/jops/main.go | 34 ------------ cmd/jops/root.go | 15 ------ internal/jira/v2/issue/create/create.go | 22 ++++++++ internal/jira/v2/issue/create/structs.go | 22 ++++++++ .../v2/issue => pkg/jira/v2}/done/done.go | 0 .../v2/issue => pkg/jira/v2}/done/structs.go | 0 9 files changed, 111 insertions(+), 66 deletions(-) create mode 100644 cmd/jops/create.go create mode 100644 internal/jira/v2/issue/create/create.go create mode 100644 internal/jira/v2/issue/create/structs.go rename {internal/jira/v2/issue => pkg/jira/v2}/done/done.go (100%) rename {internal/jira/v2/issue => pkg/jira/v2}/done/structs.go (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad437bc..b36e2ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.3.0] - 2021-08-18 + +### Added + +- Create a Jira issue. + +### Changed + +- The done method could be called be imported and used in other tools. + ## [0.2.0] - 2021-08-18 ### Added @@ -20,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Issue JQL queries. - Describe in README how to use the jops library. -[Unreleased]: https://github.com/030/jops/compare/0.2.0...HEAD +[Unreleased]: https://github.com/030/jops/compare/0.3.0...HEAD +[0.3.0]: https://github.com/030/jops/compare/0.2.0...0.3.0 [0.2.0]: https://github.com/030/jops/compare/0.1.0...0.2.0 [0.1.0]: https://github.com/030/jops/releases/tag/0.1.0 diff --git a/cmd/jops/create.go b/cmd/jops/create.go new file mode 100644 index 0000000..08efc9c --- /dev/null +++ b/cmd/jops/create.go @@ -0,0 +1,54 @@ +package main + +import ( + "fmt" + "log" + + "github.com/030/jops/internal/jira/v2/issue/create" + "github.com/spf13/cobra" +) + +// createCmd represents the create command +var createCmd = &cobra.Command{ + Use: "create", + Short: "Create a Jira issue", + Long: `A longer description that spans multiple lines and likely contains examples +and usage of using your command. For example: + +Cobra is a CLI library for Go that empowers applications. +This application is a tool to generate the needed files +to quickly create a Cobra application.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("create called") + j := create.Jira{User: user, Pass: pass, FQDN: fqdn, Project: project, Summary: summary, Description: description} + if err := j.Create(); err != nil { + log.Fatal(err) + } + }, +} + +var description, summary string + +func init() { + rootCmd.AddCommand(createCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // createCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // createCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + + createCmd.PersistentFlags().StringVarP(&summary, "summary", "s", "", "The summary of the Jira issue") + if err := createCmd.MarkPersistentFlagRequired("summary"); err != nil { + log.Fatal(err) + } + + createCmd.PersistentFlags().StringVarP(&description, "description", "d", "", "The description of the Jira issue") + if err := createCmd.MarkPersistentFlagRequired("description"); err != nil { + log.Fatal(err) + } +} diff --git a/cmd/jops/done.go b/cmd/jops/done.go index 18e8a50..bedf102 100644 --- a/cmd/jops/done.go +++ b/cmd/jops/done.go @@ -1,25 +1,10 @@ -/* -Copyright © 2021 NAME HERE - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ package main import ( "fmt" "log" - "github.com/030/jops/internal/jira/v2/issue/done" + "github.com/030/jops/pkg/jira/v2/done" "github.com/spf13/cobra" ) diff --git a/cmd/jops/main.go b/cmd/jops/main.go index 8d6969f..736ef31 100644 --- a/cmd/jops/main.go +++ b/cmd/jops/main.go @@ -1,37 +1,3 @@ -// package main - -// import ( -// "github.com/030/jops/internal/jira/issue" -// "github.com/030/jops/internal/jira/project" -// ) - -// func main() { -// project.Get() - -// issue.Get() - -// issue.Transitions() - -// issue.Done() - -// // issue.Create() -// } - -/* -Copyright © 2021 NAME HERE - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ package main func main() { diff --git a/cmd/jops/root.go b/cmd/jops/root.go index 22ca082..afdbbfd 100644 --- a/cmd/jops/root.go +++ b/cmd/jops/root.go @@ -1,18 +1,3 @@ -/* -Copyright © 2021 NAME HERE - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ package main import ( diff --git a/internal/jira/v2/issue/create/create.go b/internal/jira/v2/issue/create/create.go new file mode 100644 index 0000000..266681e --- /dev/null +++ b/internal/jira/v2/issue/create/create.go @@ -0,0 +1,22 @@ +package create + +import "github.com/030/jops/internal/pkg/httprequest" + +func (j *Jira) Create() error { + fields := Fields{ + Description: j.Description, + Summary: j.Summary, + Issuetype: Issuetype{"Story"}, + Project: Project{j.Project}, + } + data := Payload{ + Fields: fields, + } + + htj := httprequest.Jira{APIVersion: "2", Data: data, Method: "POST", FQDN: j.FQDN, User: j.User, Pass: j.Pass} + if err := htj.ConstructAndInitiate(); err != nil { + return err + } + + return nil +} diff --git a/internal/jira/v2/issue/create/structs.go b/internal/jira/v2/issue/create/structs.go new file mode 100644 index 0000000..7b499a4 --- /dev/null +++ b/internal/jira/v2/issue/create/structs.go @@ -0,0 +1,22 @@ +package create + +type Jira struct { + User, Pass, FQDN, Project, Summary, Description string +} + +type Payload struct { + Fields Fields `json:"fields"` +} +type Issuetype struct { + ID string `json:"name"` +} +type Project struct { + ID string `json:"key"` +} + +type Fields struct { + Description string `json:"description"` + Issuetype Issuetype `json:"issuetype"` + Project Project `json:"project"` + Summary string `json:"summary"` +} diff --git a/internal/jira/v2/issue/done/done.go b/pkg/jira/v2/done/done.go similarity index 100% rename from internal/jira/v2/issue/done/done.go rename to pkg/jira/v2/done/done.go diff --git a/internal/jira/v2/issue/done/structs.go b/pkg/jira/v2/done/structs.go similarity index 100% rename from internal/jira/v2/issue/done/structs.go rename to pkg/jira/v2/done/structs.go