Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
boilr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
boilr
Commits
024153dc
Commit
024153dc
authored
8 years ago
by
Tamer Tas
Browse files
Options
Downloads
Patches
Plain Diff
pkg/cmd: remove `report` command
parent
912d9da4
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/cmd/report.go
+0
-154
0 additions, 154 deletions
pkg/cmd/report.go
pkg/cmd/root.go
+0
-2
0 additions, 2 deletions
pkg/cmd/root.go
with
0 additions
and
156 deletions
pkg/cmd/report.go
deleted
100644 → 0
+
0
−
154
View file @
912d9da4
package
cmd
import
(
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
"path/filepath"
"strings"
"golang.org/x/crypto/ssh/terminal"
"github.com/google/go-github/github"
cli
"github.com/spf13/cobra"
"github.com/tmrts/boilr/pkg/boilr"
"github.com/tmrts/boilr/pkg/util/exit"
"github.com/tmrts/boilr/pkg/util/validate"
)
type
transport
struct
{
Username
string
Password
string
}
func
(
t
transport
)
RoundTrip
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
req
.
SetBasicAuth
(
t
.
Username
,
t
.
Password
)
return
http
.
DefaultTransport
.
RoundTrip
(
req
)
}
func
(
t
*
transport
)
Client
()
*
http
.
Client
{
return
&
http
.
Client
{
Transport
:
t
}
}
func
readPassword
()
(
transport
,
error
)
{
var
name
string
fmt
.
Printf
(
"Username for github: "
)
fmt
.
Scanf
(
"%s"
,
&
name
)
fmt
.
Printf
(
"Password for %s: "
,
name
)
pass
,
err
:=
terminal
.
ReadPassword
(
int
(
os
.
Stdin
.
Fd
()))
if
err
!=
nil
{
return
transport
{},
err
}
fmt
.
Println
()
return
transport
{
Username
:
name
,
Password
:
string
(
pass
),
},
nil
}
func
getIssue
()
(
*
github
.
IssueRequest
,
error
)
{
dir
,
err
:=
ioutil
.
TempDir
(
""
,
"boilr-report"
)
if
err
!=
nil
{
return
nil
,
err
}
defer
os
.
RemoveAll
(
dir
)
fname
:=
filepath
.
Join
(
dir
,
"issue.markdown"
)
f
,
err
:=
os
.
Create
(
fname
)
if
err
!=
nil
{
return
nil
,
err
}
_
,
err
=
io
.
WriteString
(
f
,
"<!-- Replace with Issue Title -->
\n\n
<!-- Replace with Issue Body -->"
)
if
err
!=
nil
{
return
nil
,
err
}
f
.
Close
()
cmd
:=
exec
.
Command
(
"vi"
,
fname
)
cmd
.
Stdin
=
os
.
Stdin
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stderr
=
os
.
Stderr
if
err
=
cmd
.
Start
();
err
!=
nil
{
return
nil
,
err
}
if
err
=
cmd
.
Wait
();
err
!=
nil
{
return
nil
,
err
}
issueFile
,
err
:=
os
.
Open
(
fname
)
if
err
!=
nil
{
return
nil
,
err
}
defer
issueFile
.
Close
()
buf
,
err
:=
ioutil
.
ReadAll
(
issueFile
)
if
err
!=
nil
{
return
nil
,
err
}
slices
:=
strings
.
SplitAfterN
(
string
(
buf
),
"
\n
"
,
2
)
// TODO Abort if any field is empty
title
,
body
:=
slices
[
0
],
slices
[
1
]
title
=
strings
.
TrimPrefix
(
title
,
"
\n
"
)
title
=
strings
.
TrimSuffix
(
title
,
"
\n
"
)
body
=
strings
.
TrimPrefix
(
body
,
"
\n
"
)
body
=
strings
.
TrimSuffix
(
body
,
"
\n
"
)
if
title
==
""
||
body
==
""
{
return
nil
,
fmt
.
Errorf
(
"issue field is empty, report aborting"
)
}
return
&
github
.
IssueRequest
{
Title
:
&
title
,
Body
:
&
body
,
},
nil
}
func
createIssue
()
(
string
,
error
)
{
req
,
err
:=
getIssue
()
if
err
!=
nil
{
return
""
,
err
}
t
,
err
:=
readPassword
()
if
err
!=
nil
{
return
""
,
err
}
client
:=
github
.
NewClient
(
t
.
Client
())
issue
,
_
,
err
:=
client
.
Issues
.
Create
(
boilr
.
GithubOwner
,
boilr
.
GithubRepo
,
req
)
if
err
!=
nil
{
return
""
,
err
}
return
*
issue
.
HTMLURL
,
nil
}
// Report contains the cli-command for creating github issues.
var
Report
=
&
cli
.
Command
{
Use
:
"report"
,
Short
:
"Create an issue in the github repository"
,
Run
:
func
(
c
*
cli
.
Command
,
args
[]
string
)
{
MustValidateArgs
(
args
,
[]
validate
.
Argument
{})
url
,
err
:=
createIssue
()
if
err
!=
nil
{
exit
.
Error
(
fmt
.
Errorf
(
"Failed to create an issue: %v"
,
err
))
}
exit
.
OK
(
"Successfully created an issue %v"
,
url
)
},
}
This diff is collapsed.
Click to expand it.
pkg/cmd/root.go
+
0
−
2
View file @
024153dc
...
...
@@ -44,8 +44,6 @@ func Run() {
Root
.
AddCommand
(
ConfigureBashCompletion
)
Root
.
AddCommand
(
Report
)
Root
.
AddCommand
(
Template
)
Version
.
PersistentFlags
()
.
BoolP
(
"dont-prettify"
,
""
,
false
,
"Only print the version without fancy formatting"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment