Skip to content

Commit

Permalink
Merge pull request #9 from 030/1-create-issue
Browse files Browse the repository at this point in the history
[GH-1] Create a Jira issue.
  • Loading branch information
030 authored Aug 18, 2021
2 parents 2242284 + 612f8e9 commit b1e2a36
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 66 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
54 changes: 54 additions & 0 deletions cmd/jops/create.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
17 changes: 1 addition & 16 deletions cmd/jops/done.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
/*
Copyright © 2021 NAME HERE <EMAIL ADDRESS>
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"
)

Expand Down
34 changes: 0 additions & 34 deletions cmd/jops/main.go
Original file line number Diff line number Diff line change
@@ -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 <EMAIL ADDRESS>
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() {
Expand Down
15 changes: 0 additions & 15 deletions cmd/jops/root.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2021 NAME HERE <EMAIL ADDRESS>
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 (
Expand Down
22 changes: 22 additions & 0 deletions internal/jira/v2/issue/create/create.go
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 22 additions & 0 deletions internal/jira/v2/issue/create/structs.go
Original file line number Diff line number Diff line change
@@ -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"`
}
File renamed without changes.
File renamed without changes.

0 comments on commit b1e2a36

Please sign in to comment.