Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
git-bug
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
MichaelMure
git-bug
Commits
06abb5a5
Commit
06abb5a5
authored
5 years ago
by
Amine Hilaly
Browse files
Options
Downloads
Patches
Plain Diff
bridge/gitlab: add gitlab bridge configuration
parent
da2d7970
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
bridge/core/token.go
+2
-2
2 additions, 2 deletions
bridge/core/token.go
bridge/gitlab/config.go
+71
-3
71 additions, 3 deletions
bridge/gitlab/config.go
bridge/gitlab/export.go
+1
-1
1 addition, 1 deletion
bridge/gitlab/export.go
bridge/gitlab/import.go
+1
-1
1 addition, 1 deletion
bridge/gitlab/import.go
with
75 additions
and
7 deletions
bridge/core/token.go
+
2
−
2
View file @
06abb5a5
...
@@ -237,12 +237,12 @@ func TokenExist(repo repository.RepoCommon, value string) bool {
...
@@ -237,12 +237,12 @@ func TokenExist(repo repository.RepoCommon, value string) bool {
// TokenExistWithTarget same as TokenExist but restrict search for a given target
// TokenExistWithTarget same as TokenExist but restrict search for a given target
func
TokenExistWithTarget
(
repo
repository
.
RepoCommon
,
value
string
,
target
string
)
bool
{
func
TokenExistWithTarget
(
repo
repository
.
RepoCommon
,
value
string
,
target
string
)
bool
{
tokens
,
err
:=
LoadTokens
(
repo
)
tokens
,
err
:=
LoadTokens
WithTarget
(
repo
,
target
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
return
false
}
}
for
_
,
token
:=
range
tokens
{
for
_
,
token
:=
range
tokens
{
if
token
.
Value
==
value
&&
token
.
Target
==
target
{
if
token
.
Value
==
value
{
return
true
return
true
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
bridge/gitlab/config.go
+
71
−
3
View file @
06abb5a5
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"github.com/xanzy/go-gitlab"
"github.com/xanzy/go-gitlab"
"github.com/MichaelMure/git-bug/bridge/core"
"github.com/MichaelMure/git-bug/bridge/core"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/repository"
"github.com/MichaelMure/git-bug/repository"
)
)
...
@@ -32,6 +33,8 @@ func (g *Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams)
...
@@ -32,6 +33,8 @@ func (g *Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams)
var
err
error
var
err
error
var
url
string
var
url
string
var
token
string
var
token
string
var
tokenId
entity
.
Id
var
tokenObj
*
core
.
Token
if
(
params
.
Token
!=
""
||
params
.
TokenStdin
)
&&
params
.
URL
==
""
{
if
(
params
.
Token
!=
""
||
params
.
TokenStdin
)
&&
params
.
URL
==
""
{
return
nil
,
fmt
.
Errorf
(
"you must provide a project URL to configure this bridge with a token"
)
return
nil
,
fmt
.
Errorf
(
"you must provide a project URL to configure this bridge with a token"
)
...
@@ -65,21 +68,38 @@ func (g *Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams)
...
@@ -65,21 +68,38 @@ func (g *Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams)
return
nil
,
fmt
.
Errorf
(
"reading from stdin: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"reading from stdin: %v"
,
err
)
}
}
token
=
strings
.
TrimSuffix
(
token
,
"
\n
"
)
token
=
strings
.
TrimSuffix
(
token
,
"
\n
"
)
}
else
if
params
.
TokenId
!=
""
{
tokenId
=
entity
.
Id
(
params
.
TokenId
)
}
else
{
}
else
{
token
,
err
=
promptToken
(
)
token
Obj
,
err
=
promptToken
Options
(
repo
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"token prompt"
)
return
nil
,
errors
.
Wrap
(
err
,
"token prompt"
)
}
}
}
}
if
token
!=
""
{
tokenObj
,
err
=
core
.
LoadOrCreateToken
(
repo
,
target
,
token
)
if
err
!=
nil
{
return
nil
,
err
}
}
else
if
tokenId
!=
""
{
tokenObj
,
err
=
core
.
LoadToken
(
repo
,
entity
.
Id
(
tokenId
))
if
err
!=
nil
{
return
nil
,
err
}
if
tokenObj
.
Target
!=
target
{
return
nil
,
fmt
.
Errorf
(
"token target is incompatible %s"
,
tokenObj
.
Target
)
}
}
// validate project url and get its ID
// validate project url and get its ID
id
,
err
:=
validateProjectURL
(
url
,
token
)
id
,
err
:=
validateProjectURL
(
url
,
token
Obj
.
Value
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"project validation"
)
return
nil
,
errors
.
Wrap
(
err
,
"project validation"
)
}
}
conf
[
keyProjectID
]
=
strconv
.
Itoa
(
id
)
conf
[
keyProjectID
]
=
strconv
.
Itoa
(
id
)
conf
[
k
eyToken
]
=
token
conf
[
core
.
ConfigK
eyToken
Id
]
=
token
Obj
.
ID
()
.
String
()
conf
[
core
.
ConfigKeyTarget
]
=
target
conf
[
core
.
ConfigKeyTarget
]
=
target
err
=
g
.
ValidateConfig
(
conf
)
err
=
g
.
ValidateConfig
(
conf
)
...
@@ -108,6 +128,54 @@ func (g *Gitlab) ValidateConfig(conf core.Configuration) error {
...
@@ -108,6 +128,54 @@ func (g *Gitlab) ValidateConfig(conf core.Configuration) error {
return
nil
return
nil
}
}
func
promptTokenOptions
(
repo
repository
.
RepoCommon
)
(
*
core
.
Token
,
error
)
{
for
{
tokens
,
err
:=
core
.
LoadTokensWithTarget
(
repo
,
target
)
if
err
!=
nil
{
return
nil
,
err
}
fmt
.
Println
()
fmt
.
Println
(
"[1]: user provided token"
)
if
len
(
tokens
)
>
0
{
fmt
.
Println
(
"known tokens for Gitlab:"
)
for
i
,
token
:=
range
tokens
{
if
token
.
Target
==
target
{
fmt
.
Printf
(
"[%d]: %s
\n
"
,
i
+
2
,
token
.
ID
())
}
}
}
fmt
.
Print
(
"Select option: "
)
line
,
err
:=
bufio
.
NewReader
(
os
.
Stdin
)
.
ReadString
(
'\n'
)
fmt
.
Println
()
if
err
!=
nil
{
return
nil
,
err
}
line
=
strings
.
TrimRight
(
line
,
"
\n
"
)
index
,
err
:=
strconv
.
Atoi
(
line
)
if
err
!=
nil
||
index
<
1
||
index
>
len
(
tokens
)
+
1
{
fmt
.
Println
(
"invalid input"
)
continue
}
var
token
string
switch
index
{
case
1
:
token
,
err
=
promptToken
()
if
err
!=
nil
{
return
nil
,
err
}
default
:
return
tokens
[
index
-
2
],
nil
}
return
core
.
LoadOrCreateToken
(
repo
,
target
,
token
)
}
}
func
promptToken
()
(
string
,
error
)
{
func
promptToken
()
(
string
,
error
)
{
fmt
.
Println
(
"You can generate a new token by visiting https://gitlab.com/profile/personal_access_tokens."
)
fmt
.
Println
(
"You can generate a new token by visiting https://gitlab.com/profile/personal_access_tokens."
)
fmt
.
Println
(
"Choose 'Create personal access token' and set the necessary access scope for your repository."
)
fmt
.
Println
(
"Choose 'Create personal access token' and set the necessary access scope for your repository."
)
...
...
This diff is collapsed.
Click to expand it.
bridge/gitlab/export.go
+
1
−
1
View file @
06abb5a5
...
@@ -79,7 +79,7 @@ func (ge *gitlabExporter) ExportAll(ctx context.Context, repo *cache.RepoCache,
...
@@ -79,7 +79,7 @@ func (ge *gitlabExporter) ExportAll(ctx context.Context, repo *cache.RepoCache,
return
nil
,
err
return
nil
,
err
}
}
ge
.
identityToken
[
user
.
Id
()
.
String
()]
=
ge
.
conf
[
k
eyToken
]
ge
.
identityToken
[
user
.
Id
()
.
String
()]
=
ge
.
conf
[
core
.
ConfigK
eyToken
]
// get repository node id
// get repository node id
ge
.
repositoryID
=
ge
.
conf
[
keyProjectID
]
ge
.
repositoryID
=
ge
.
conf
[
keyProjectID
]
...
...
This diff is collapsed.
Click to expand it.
bridge/gitlab/import.go
+
1
−
1
View file @
06abb5a5
...
@@ -34,7 +34,7 @@ func (gi *gitlabImporter) Init(conf core.Configuration) error {
...
@@ -34,7 +34,7 @@ func (gi *gitlabImporter) Init(conf core.Configuration) error {
// ImportAll iterate over all the configured repository issues (notes) and ensure the creation
// ImportAll iterate over all the configured repository issues (notes) and ensure the creation
// of the missing issues / comments / label events / title changes ...
// of the missing issues / comments / label events / title changes ...
func
(
gi
*
gitlabImporter
)
ImportAll
(
ctx
context
.
Context
,
repo
*
cache
.
RepoCache
,
since
time
.
Time
)
(
<-
chan
core
.
ImportResult
,
error
)
{
func
(
gi
*
gitlabImporter
)
ImportAll
(
ctx
context
.
Context
,
repo
*
cache
.
RepoCache
,
since
time
.
Time
)
(
<-
chan
core
.
ImportResult
,
error
)
{
gi
.
iterator
=
NewIterator
(
ctx
,
10
,
gi
.
conf
[
keyProjectID
],
gi
.
conf
[
k
eyToken
],
since
)
gi
.
iterator
=
NewIterator
(
ctx
,
10
,
gi
.
conf
[
keyProjectID
],
gi
.
conf
[
core
.
ConfigK
eyToken
],
since
)
out
:=
make
(
chan
core
.
ImportResult
)
out
:=
make
(
chan
core
.
ImportResult
)
gi
.
out
=
out
gi
.
out
=
out
...
...
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