Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
5f86a084
Commit
5f86a084
authored
Jul 06, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consider that a GH exists only if both `ref`, and `sha` exist
parent
4e5de3e6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
18 deletions
+31
-18
lib/gitlab/github_import/branch_formatter.rb
lib/gitlab/github_import/branch_formatter.rb
+8
-4
spec/lib/gitlab/github_import/branch_formatter_spec.rb
spec/lib/gitlab/github_import/branch_formatter_spec.rb
+13
-6
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
+10
-8
No files found.
lib/gitlab/github_import/branch_formatter.rb
View file @
5f86a084
...
...
@@ -4,7 +4,7 @@ module Gitlab
delegate
:repo
,
:sha
,
:ref
,
to: :raw_data
def
exists?
project
.
repository
.
branch_exists?
(
ref
)
branch_exists?
&&
commit_exists?
end
def
name
...
...
@@ -15,11 +15,15 @@ module Gitlab
repo
.
present?
end
def
valid?
repo
.
present?
private
def
branch_exists?
project
.
repository
.
branch_exists?
(
ref
)
end
private
def
commit_exists?
project
.
repository
.
commit
(
sha
).
present?
end
def
short_id
sha
.
to_s
[
0
..
7
]
...
...
spec/lib/gitlab/github_import/branch_formatter_spec.rb
View file @
5f86a084
...
...
@@ -2,17 +2,18 @@ require 'spec_helper'
describe
Gitlab
::
GithubImport
::
BranchFormatter
,
lib:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:commit
)
{
create
(
:commit
,
project:
project
)
}
let
(
:repo
)
{
double
}
let
(
:raw
)
do
{
ref:
'feature'
,
repo:
repo
,
sha:
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
sha:
commit
.
id
}
end
describe
'#exists?'
do
it
'returns true when b
ranch
exists'
do
it
'returns true when b
oth branch, and commit
exists'
do
branch
=
described_class
.
new
(
project
,
double
(
raw
))
expect
(
branch
.
exists?
).
to
eq
true
...
...
@@ -23,6 +24,12 @@ describe Gitlab::GithubImport::BranchFormatter, lib: true do
expect
(
branch
.
exists?
).
to
eq
false
end
it
'returns false when commit does not exist'
do
branch
=
described_class
.
new
(
project
,
double
(
raw
.
merge
(
sha:
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
)))
expect
(
branch
.
exists?
).
to
eq
false
end
end
describe
'#name'
do
...
...
@@ -33,7 +40,7 @@ describe Gitlab::GithubImport::BranchFormatter, lib: true do
end
it
'returns formatted ref when branch does not exist'
do
branch
=
described_class
.
new
(
project
,
double
(
raw
.
merge
(
ref:
'removed-branch'
)))
branch
=
described_class
.
new
(
project
,
double
(
raw
.
merge
(
ref:
'removed-branch'
,
sha:
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
)))
expect
(
branch
.
name
).
to
eq
'removed-branch-2e5d3239'
end
...
...
@@ -51,18 +58,18 @@ describe Gitlab::GithubImport::BranchFormatter, lib: true do
it
'returns raw sha'
do
branch
=
described_class
.
new
(
project
,
double
(
raw
))
expect
(
branch
.
sha
).
to
eq
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
expect
(
branch
.
sha
).
to
eq
commit
.
id
end
end
describe
'#valid?'
do
it
'returns true when r
epository exists
'
do
it
'returns true when r
aw repo is present
'
do
branch
=
described_class
.
new
(
project
,
double
(
raw
))
expect
(
branch
.
valid?
).
to
eq
true
end
it
'returns false when r
epository does not exist
'
do
it
'returns false when r
aw repo is blank
'
do
branch
=
described_class
.
new
(
project
,
double
(
raw
.
merge
(
repo:
nil
)))
expect
(
branch
.
valid?
).
to
eq
false
...
...
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
View file @
5f86a084
...
...
@@ -2,11 +2,13 @@ require 'spec_helper'
describe
Gitlab
::
GithubImport
::
PullRequestFormatter
,
lib:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:source_sha
)
{
create
(
:commit
,
project:
project
).
id
}
let
(
:target_sha
)
{
create
(
:commit
,
project:
project
,
git_commit:
RepoHelpers
.
another_sample_commit
).
id
}
let
(
:repository
)
{
double
(
id:
1
,
fork:
false
)
}
let
(
:source_repo
)
{
repository
}
let
(
:source_branch
)
{
double
(
ref:
'feature'
,
repo:
source_repo
,
sha:
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
)
}
let
(
:source_branch
)
{
double
(
ref:
'feature'
,
repo:
source_repo
,
sha:
source_sha
)
}
let
(
:target_repo
)
{
repository
}
let
(
:target_branch
)
{
double
(
ref:
'master'
,
repo:
target_repo
,
sha:
'8ffb3c15a5475e59ae909384297fede4badcb4c7'
)
}
let
(
:target_branch
)
{
double
(
ref:
'master'
,
repo:
target_repo
,
sha:
target_sha
)
}
let
(
:octocat
)
{
double
(
id:
123456
,
login:
'octocat'
)
}
let
(
:created_at
)
{
DateTime
.
strptime
(
'2011-01-26T19:01:12Z'
)
}
let
(
:updated_at
)
{
DateTime
.
strptime
(
'2011-01-27T19:01:12Z'
)
}
...
...
@@ -41,10 +43,10 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
description:
"*Created by: octocat*
\n\n
Please pull these awesome changes"
,
source_project:
project
,
source_branch:
'feature'
,
head_source_sha:
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
,
head_source_sha:
source_sha
,
target_project:
project
,
target_branch:
'master'
,
base_target_sha:
'8ffb3c15a5475e59ae909384297fede4badcb4c7'
,
base_target_sha:
target_sha
,
state:
'opened'
,
milestone:
nil
,
author_id:
project
.
creator_id
,
...
...
@@ -68,10 +70,10 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
description:
"*Created by: octocat*
\n\n
Please pull these awesome changes"
,
source_project:
project
,
source_branch:
'feature'
,
head_source_sha:
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
,
head_source_sha:
source_sha
,
target_project:
project
,
target_branch:
'master'
,
base_target_sha:
'8ffb3c15a5475e59ae909384297fede4badcb4c7'
,
base_target_sha:
target_sha
,
state:
'closed'
,
milestone:
nil
,
author_id:
project
.
creator_id
,
...
...
@@ -95,10 +97,10 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
description:
"*Created by: octocat*
\n\n
Please pull these awesome changes"
,
source_project:
project
,
source_branch:
'feature'
,
head_source_sha:
'2e5d3239642f9161dcbbc4b70a211a68e5e45e2b'
,
head_source_sha:
source_sha
,
target_project:
project
,
target_branch:
'master'
,
base_target_sha:
'8ffb3c15a5475e59ae909384297fede4badcb4c7'
,
base_target_sha:
target_sha
,
state:
'merged'
,
milestone:
nil
,
author_id:
project
.
creator_id
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment