BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
53a1d705
Commit
53a1d705
authored
Apr 18, 2016
by
Robert Speicher
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gh-import-milestones' into 'master'
Import milestones from GitHub Closes #13421 See merge request !3797
parents
17b60d68
0ed07587
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
222 additions
and
29 deletions
+222
-29
CHANGELOG
CHANGELOG
+1
-0
importer.rb
lib/gitlab/github_import/importer.rb
+12
-1
issue_formatter.rb
lib/gitlab/github_import/issue_formatter.rb
+7
-0
milestone_formatter.rb
lib/gitlab/github_import/milestone_formatter.rb
+48
-0
pull_request_formatter.rb
lib/gitlab/github_import/pull_request_formatter.rb
+7
-0
issue_formatter_spec.rb
spec/lib/gitlab/github_import/issue_formatter_spec.rb
+28
-10
milestone_formatter_spec.rb
spec/lib/gitlab/github_import/milestone_formatter_spec.rb
+82
-0
pull_request_formatter_spec.rb
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
+37
-18
No files found.
CHANGELOG
View file @
53a1d705
...
@@ -86,6 +86,7 @@ v 8.7.0 (unreleased)
...
@@ -86,6 +86,7 @@ v 8.7.0 (unreleased)
- Updated print style for issues
- Updated print style for issues
- Use GitHub Issue/PR number as iid to keep references
- Use GitHub Issue/PR number as iid to keep references
- Import GitHub labels
- Import GitHub labels
- Import GitHub milestones
v 8.6.6
v 8.6.6
- Expire the exists cache before deletion to ensure project dir actually exists (Stan Hu). !3413
- Expire the exists cache before deletion to ensure project dir actually exists (Stan Hu). !3413
...
...
lib/gitlab/github_import/importer.rb
View file @
53a1d705
...
@@ -16,7 +16,8 @@ module Gitlab
...
@@ -16,7 +16,8 @@ module Gitlab
end
end
def
execute
def
execute
import_labels
&&
import_issues
&&
import_pull_requests
&&
import_wiki
import_labels
&&
import_milestones
&&
import_issues
&&
import_pull_requests
&&
import_wiki
end
end
private
private
...
@@ -35,6 +36,16 @@ module Gitlab
...
@@ -35,6 +36,16 @@ module Gitlab
raise
Projects
::
ImportService
::
Error
,
e
.
message
raise
Projects
::
ImportService
::
Error
,
e
.
message
end
end
def
import_milestones
client
.
list_milestones
(
project
.
import_source
,
state: :all
).
each
do
|
raw_data
|
Milestone
.
create!
(
MilestoneFormatter
.
new
(
project
,
raw_data
).
attributes
)
end
true
rescue
ActiveRecord
::
RecordInvalid
=>
e
raise
Projects
::
ImportService
::
Error
,
e
.
message
end
def
import_issues
def
import_issues
client
.
list_issues
(
project
.
import_source
,
state: :all
,
client
.
list_issues
(
project
.
import_source
,
state: :all
,
sort: :created
,
sort: :created
,
...
...
lib/gitlab/github_import/issue_formatter.rb
View file @
53a1d705
...
@@ -5,6 +5,7 @@ module Gitlab
...
@@ -5,6 +5,7 @@ module Gitlab
{
{
iid:
number
,
iid:
number
,
project:
project
,
project:
project
,
milestone:
milestone
,
title:
raw_data
.
title
,
title:
raw_data
.
title
,
description:
description
,
description:
description
,
state:
state
,
state:
state
,
...
@@ -55,6 +56,12 @@ module Gitlab
...
@@ -55,6 +56,12 @@ module Gitlab
@formatter
.
author_line
(
author
)
+
body
@formatter
.
author_line
(
author
)
+
body
end
end
def
milestone
if
raw_data
.
milestone
.
present?
project
.
milestones
.
find_by
(
iid:
raw_data
.
milestone
.
number
)
end
end
def
state
def
state
raw_data
.
state
==
'closed'
?
'closed'
:
'opened'
raw_data
.
state
==
'closed'
?
'closed'
:
'opened'
end
end
...
...
lib/gitlab/github_import/milestone_formatter.rb
0 → 100644
View file @
53a1d705
module
Gitlab
module
GithubImport
class
MilestoneFormatter
<
BaseFormatter
def
attributes
{
iid:
number
,
project:
project
,
title:
title
,
description:
description
,
due_date:
due_date
,
state:
state
,
created_at:
created_at
,
updated_at:
updated_at
}
end
private
def
number
raw_data
.
number
end
def
title
raw_data
.
title
end
def
description
raw_data
.
description
end
def
due_date
raw_data
.
due_on
end
def
state
raw_data
.
state
==
'closed'
?
'closed'
:
'active'
end
def
created_at
raw_data
.
created_at
end
def
updated_at
state
==
'closed'
?
raw_data
.
closed_at
:
raw_data
.
updated_at
end
end
end
end
lib/gitlab/github_import/pull_request_formatter.rb
View file @
53a1d705
...
@@ -11,6 +11,7 @@ module Gitlab
...
@@ -11,6 +11,7 @@ module Gitlab
target_project:
target_project
,
target_project:
target_project
,
target_branch:
target_branch
.
name
,
target_branch:
target_branch
.
name
,
state:
state
,
state:
state
,
milestone:
milestone
,
author_id:
author_id
,
author_id:
author_id
,
assignee_id:
assignee_id
,
assignee_id:
assignee_id
,
created_at:
raw_data
.
created_at
,
created_at:
raw_data
.
created_at
,
...
@@ -58,6 +59,12 @@ module Gitlab
...
@@ -58,6 +59,12 @@ module Gitlab
formatter
.
author_line
(
author
)
+
body
formatter
.
author_line
(
author
)
+
body
end
end
def
milestone
if
raw_data
.
milestone
.
present?
project
.
milestones
.
find_by
(
iid:
raw_data
.
milestone
.
number
)
end
end
def
source_project
def
source_project
project
project
end
end
...
...
spec/lib/gitlab/github_import/issue_formatter_spec.rb
View file @
53a1d705
...
@@ -2,13 +2,14 @@ require 'spec_helper'
...
@@ -2,13 +2,14 @@ require 'spec_helper'
describe
Gitlab
::
GithubImport
::
IssueFormatter
,
lib:
true
do
describe
Gitlab
::
GithubImport
::
IssueFormatter
,
lib:
true
do
let!
(
:project
)
{
create
(
:project
,
namespace:
create
(
:namespace
,
path:
'octocat'
))
}
let!
(
:project
)
{
create
(
:project
,
namespace:
create
(
:namespace
,
path:
'octocat'
))
}
let
(
:octocat
)
{
OpenStruct
.
new
(
id:
123456
,
login:
'octocat'
)
}
let
(
:octocat
)
{
double
(
id:
123456
,
login:
'octocat'
)
}
let
(
:created_at
)
{
DateTime
.
strptime
(
'2011-01-26T19:01:12Z'
)
}
let
(
:created_at
)
{
DateTime
.
strptime
(
'2011-01-26T19:01:12Z'
)
}
let
(
:updated_at
)
{
DateTime
.
strptime
(
'2011-01-27T19:01:12Z'
)
}
let
(
:updated_at
)
{
DateTime
.
strptime
(
'2011-01-27T19:01:12Z'
)
}
let
(
:base_data
)
do
let
(
:base_data
)
do
{
{
number:
1347
,
number:
1347
,
milestone:
nil
,
state:
'open'
,
state:
'open'
,
title:
'Found a bug'
,
title:
'Found a bug'
,
body:
"I'm having a problem with this."
,
body:
"I'm having a problem with this."
,
...
@@ -26,12 +27,13 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
...
@@ -26,12 +27,13 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
describe
'#attributes'
do
describe
'#attributes'
do
context
'when issue is open'
do
context
'when issue is open'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
state:
'open'
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
state:
'open'
))
}
it
'returns formatted attributes'
do
it
'returns formatted attributes'
do
expected
=
{
expected
=
{
iid:
1347
,
iid:
1347
,
project:
project
,
project:
project
,
milestone:
nil
,
title:
'Found a bug'
,
title:
'Found a bug'
,
description:
"*Created by: octocat*
\n\n
I'm having a problem with this."
,
description:
"*Created by: octocat*
\n\n
I'm having a problem with this."
,
state:
'opened'
,
state:
'opened'
,
...
@@ -47,12 +49,13 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
...
@@ -47,12 +49,13 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
context
'when issue is closed'
do
context
'when issue is closed'
do
let
(
:closed_at
)
{
DateTime
.
strptime
(
'2011-01-28T19:01:12Z'
)
}
let
(
:closed_at
)
{
DateTime
.
strptime
(
'2011-01-28T19:01:12Z'
)
}
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
state:
'closed'
,
closed_at:
closed_at
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
state:
'closed'
,
closed_at:
closed_at
))
}
it
'returns formatted attributes'
do
it
'returns formatted attributes'
do
expected
=
{
expected
=
{
iid:
1347
,
iid:
1347
,
project:
project
,
project:
project
,
milestone:
nil
,
title:
'Found a bug'
,
title:
'Found a bug'
,
description:
"*Created by: octocat*
\n\n
I'm having a problem with this."
,
description:
"*Created by: octocat*
\n\n
I'm having a problem with this."
,
state:
'closed'
,
state:
'closed'
,
...
@@ -67,7 +70,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
...
@@ -67,7 +70,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
end
end
context
'when it is assigned to someone'
do
context
'when it is assigned to someone'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
assignee:
octocat
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
assignee:
octocat
))
}
it
'returns nil as assignee_id when is not a GitLab user'
do
it
'returns nil as assignee_id when is not a GitLab user'
do
expect
(
issue
.
attributes
.
fetch
(
:assignee_id
)).
to
be_nil
expect
(
issue
.
attributes
.
fetch
(
:assignee_id
)).
to
be_nil
...
@@ -80,8 +83,23 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
...
@@ -80,8 +83,23 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
end
end
end
end
context
'when it has a milestone'
do
let
(
:milestone
)
{
double
(
number:
45
)
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
milestone:
milestone
))
}
it
'returns nil when milestone does not exist'
do
expect
(
issue
.
attributes
.
fetch
(
:milestone
)).
to
be_nil
end
it
'returns milestone when it exists'
do
milestone
=
create
(
:milestone
,
project:
project
,
iid:
45
)
expect
(
issue
.
attributes
.
fetch
(
:milestone
)).
to
eq
milestone
end
end
context
'when author is a GitLab user'
do
context
'when author is a GitLab user'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
user:
octocat
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
user:
octocat
))
}
it
'returns project#creator_id as author_id when is not a GitLab user'
do
it
'returns project#creator_id as author_id when is not a GitLab user'
do
expect
(
issue
.
attributes
.
fetch
(
:author_id
)).
to
eq
project
.
creator_id
expect
(
issue
.
attributes
.
fetch
(
:author_id
)).
to
eq
project
.
creator_id
...
@@ -97,7 +115,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
...
@@ -97,7 +115,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
describe
'#has_comments?'
do
describe
'#has_comments?'
do
context
'when number of comments is greater than zero'
do
context
'when number of comments is greater than zero'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
comments:
1
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
comments:
1
))
}
it
'returns true'
do
it
'returns true'
do
expect
(
issue
.
has_comments?
).
to
eq
true
expect
(
issue
.
has_comments?
).
to
eq
true
...
@@ -105,7 +123,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
...
@@ -105,7 +123,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
end
end
context
'when number of comments is equal to zero'
do
context
'when number of comments is equal to zero'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
comments:
0
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
comments:
0
))
}
it
'returns false'
do
it
'returns false'
do
expect
(
issue
.
has_comments?
).
to
eq
false
expect
(
issue
.
has_comments?
).
to
eq
false
...
@@ -114,7 +132,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
...
@@ -114,7 +132,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
end
end
describe
'#number'
do
describe
'#number'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
number:
1347
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
number:
1347
))
}
it
'returns pull request number'
do
it
'returns pull request number'
do
expect
(
issue
.
number
).
to
eq
1347
expect
(
issue
.
number
).
to
eq
1347
...
@@ -123,7 +141,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
...
@@ -123,7 +141,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
describe
'#valid?'
do
describe
'#valid?'
do
context
'when mention a pull request'
do
context
'when mention a pull request'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
pull_request:
OpenStruct
.
new
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
pull_request:
double
))
}
it
'returns false'
do
it
'returns false'
do
expect
(
issue
.
valid?
).
to
eq
false
expect
(
issue
.
valid?
).
to
eq
false
...
@@ -131,7 +149,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
...
@@ -131,7 +149,7 @@ describe Gitlab::GithubImport::IssueFormatter, lib: true do
end
end
context
'when does not mention a pull request'
do
context
'when does not mention a pull request'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
pull_request:
nil
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
pull_request:
nil
))
}
it
'returns true'
do
it
'returns true'
do
expect
(
issue
.
valid?
).
to
eq
true
expect
(
issue
.
valid?
).
to
eq
true
...
...
spec/lib/gitlab/github_import/milestone_formatter_spec.rb
0 → 100644
View file @
53a1d705
require
'spec_helper'
describe
Gitlab
::
GithubImport
::
MilestoneFormatter
,
lib:
true
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:created_at
)
{
DateTime
.
strptime
(
'2011-01-26T19:01:12Z'
)
}
let
(
:updated_at
)
{
DateTime
.
strptime
(
'2011-01-27T19:01:12Z'
)
}
let
(
:base_data
)
do
{
number:
1347
,
state:
'open'
,
title:
'1.0'
,
description:
'Version 1.0'
,
due_on:
nil
,
created_at:
created_at
,
updated_at:
updated_at
,
closed_at:
nil
}
end
subject
(
:formatter
)
{
described_class
.
new
(
project
,
raw_data
)}
describe
'#attributes'
do
context
'when milestone is open'
do
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
state:
'open'
))
}
it
'returns formatted attributes'
do
expected
=
{
iid:
1347
,
project:
project
,
title:
'1.0'
,
description:
'Version 1.0'
,
state:
'active'
,
due_date:
nil
,
created_at:
created_at
,
updated_at:
updated_at
}
expect
(
formatter
.
attributes
).
to
eq
(
expected
)
end
end
context
'when milestone is closed'
do
let
(
:closed_at
)
{
DateTime
.
strptime
(
'2011-01-28T19:01:12Z'
)
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
state:
'closed'
,
closed_at:
closed_at
))
}
it
'returns formatted attributes'
do
expected
=
{
iid:
1347
,
project:
project
,
title:
'1.0'
,
description:
'Version 1.0'
,
state:
'closed'
,
due_date:
nil
,
created_at:
created_at
,
updated_at:
closed_at
}
expect
(
formatter
.
attributes
).
to
eq
(
expected
)
end
end
context
'when milestone has a due date'
do
let
(
:due_date
)
{
DateTime
.
strptime
(
'2011-01-28T19:01:12Z'
)
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
due_on:
due_date
))
}
it
'returns formatted attributes'
do
expected
=
{
iid:
1347
,
project:
project
,
title:
'1.0'
,
description:
'Version 1.0'
,
state:
'active'
,
due_date:
due_date
,
created_at:
created_at
,
updated_at:
updated_at
}
expect
(
formatter
.
attributes
).
to
eq
(
expected
)
end
end
end
end
spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
View file @
53a1d705
...
@@ -2,17 +2,18 @@ require 'spec_helper'
...
@@ -2,17 +2,18 @@ require 'spec_helper'
describe
Gitlab
::
GithubImport
::
PullRequestFormatter
,
lib:
true
do
describe
Gitlab
::
GithubImport
::
PullRequestFormatter
,
lib:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:repository
)
{
OpenStruct
.
new
(
id:
1
,
fork:
false
)
}
let
(
:repository
)
{
double
(
id:
1
,
fork:
false
)
}
let
(
:source_repo
)
{
repository
}
let
(
:source_repo
)
{
repository
}
let
(
:source_branch
)
{
OpenStruct
.
new
(
ref:
'feature'
,
repo:
source_repo
)
}
let
(
:source_branch
)
{
double
(
ref:
'feature'
,
repo:
source_repo
)
}
let
(
:target_repo
)
{
repository
}
let
(
:target_repo
)
{
repository
}
let
(
:target_branch
)
{
OpenStruct
.
new
(
ref:
'master'
,
repo:
target_repo
)
}
let
(
:target_branch
)
{
double
(
ref:
'master'
,
repo:
target_repo
)
}
let
(
:octocat
)
{
OpenStruct
.
new
(
id:
123456
,
login:
'octocat'
)
}
let
(
:octocat
)
{
double
(
id:
123456
,
login:
'octocat'
)
}
let
(
:created_at
)
{
DateTime
.
strptime
(
'2011-01-26T19:01:12Z'
)
}
let
(
:created_at
)
{
DateTime
.
strptime
(
'2011-01-26T19:01:12Z'
)
}
let
(
:updated_at
)
{
DateTime
.
strptime
(
'2011-01-27T19:01:12Z'
)
}
let
(
:updated_at
)
{
DateTime
.
strptime
(
'2011-01-27T19:01:12Z'
)
}
let
(
:base_data
)
do
let
(
:base_data
)
do
{
{
number:
1347
,
number:
1347
,
milestone:
nil
,
state:
'open'
,
state:
'open'
,
title:
'New feature'
,
title:
'New feature'
,
body:
'Please pull these awesome changes'
,
body:
'Please pull these awesome changes'
,
...
@@ -31,7 +32,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -31,7 +32,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
describe
'#attributes'
do
describe
'#attributes'
do
context
'when pull request is open'
do
context
'when pull request is open'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
state:
'open'
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
state:
'open'
))
}
it
'returns formatted attributes'
do
it
'returns formatted attributes'
do
expected
=
{
expected
=
{
...
@@ -43,6 +44,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -43,6 +44,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
target_project:
project
,
target_project:
project
,
target_branch:
'master'
,
target_branch:
'master'
,
state:
'opened'
,
state:
'opened'
,
milestone:
nil
,
author_id:
project
.
creator_id
,
author_id:
project
.
creator_id
,
assignee_id:
nil
,
assignee_id:
nil
,
created_at:
created_at
,
created_at:
created_at
,
...
@@ -55,7 +57,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -55,7 +57,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
context
'when pull request is closed'
do
context
'when pull request is closed'
do
let
(
:closed_at
)
{
DateTime
.
strptime
(
'2011-01-28T19:01:12Z'
)
}
let
(
:closed_at
)
{
DateTime
.
strptime
(
'2011-01-28T19:01:12Z'
)
}
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
state:
'closed'
,
closed_at:
closed_at
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
state:
'closed'
,
closed_at:
closed_at
))
}
it
'returns formatted attributes'
do
it
'returns formatted attributes'
do
expected
=
{
expected
=
{
...
@@ -67,6 +69,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -67,6 +69,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
target_project:
project
,
target_project:
project
,
target_branch:
'master'
,
target_branch:
'master'
,
state:
'closed'
,
state:
'closed'
,
milestone:
nil
,
author_id:
project
.
creator_id
,
author_id:
project
.
creator_id
,
assignee_id:
nil
,
assignee_id:
nil
,
created_at:
created_at
,
created_at:
created_at
,
...
@@ -79,7 +82,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -79,7 +82,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
context
'when pull request is merged'
do
context
'when pull request is merged'
do
let
(
:merged_at
)
{
DateTime
.
strptime
(
'2011-01-28T13:01:12Z'
)
}
let
(
:merged_at
)
{
DateTime
.
strptime
(
'2011-01-28T13:01:12Z'
)
}
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
state:
'closed'
,
merged_at:
merged_at
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
state:
'closed'
,
merged_at:
merged_at
))
}
it
'returns formatted attributes'
do
it
'returns formatted attributes'
do
expected
=
{
expected
=
{
...
@@ -91,6 +94,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -91,6 +94,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
target_project:
project
,
target_project:
project
,
target_branch:
'master'
,
target_branch:
'master'
,
state:
'merged'
,
state:
'merged'
,
milestone:
nil
,
author_id:
project
.
creator_id
,
author_id:
project
.
creator_id
,
assignee_id:
nil
,
assignee_id:
nil
,
created_at:
created_at
,
created_at:
created_at
,
...
@@ -102,7 +106,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -102,7 +106,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
end
context
'when it is assigned to someone'
do
context
'when it is assigned to someone'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
assignee:
octocat
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
assignee:
octocat
))
}
it
'returns nil as assignee_id when is not a GitLab user'
do
it
'returns nil as assignee_id when is not a GitLab user'
do
expect
(
pull_request
.
attributes
.
fetch
(
:assignee_id
)).
to
be_nil
expect
(
pull_request
.
attributes
.
fetch
(
:assignee_id
)).
to
be_nil
...
@@ -116,7 +120,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -116,7 +120,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
end
context
'when author is a GitLab user'
do
context
'when author is a GitLab user'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
user:
octocat
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
user:
octocat
))
}
it
'returns project#creator_id as author_id when is not a GitLab user'
do
it
'returns project#creator_id as author_id when is not a GitLab user'
do
expect
(
pull_request
.
attributes
.
fetch
(
:author_id
)).
to
eq
project
.
creator_id
expect
(
pull_request
.
attributes
.
fetch
(
:author_id
)).
to
eq
project
.
creator_id
...
@@ -128,10 +132,25 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -128,10 +132,25 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
expect
(
pull_request
.
attributes
.
fetch
(
:author_id
)).
to
eq
gl_user
.
id
expect
(
pull_request
.
attributes
.
fetch
(
:author_id
)).
to
eq
gl_user
.
id
end
end
end
end
context
'when it has a milestone'
do
let
(
:milestone
)
{
double
(
number:
45
)
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
milestone:
milestone
))
}
it
'returns nil when milestone does not exists'
do
expect
(
pull_request
.
attributes
.
fetch
(
:milestone
)).
to
be_nil
end
it
'returns milestone when is exists'
do
milestone
=
create
(
:milestone
,
project:
project
,
iid:
45
)
expect
(
pull_request
.
attributes
.
fetch
(
:milestone
)).
to
eq
milestone
end
end
end
end
describe
'#number'
do
describe
'#number'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
number:
1347
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
number:
1347
))
}
it
'returns pull request number'
do
it
'returns pull request number'
do
expect
(
pull_request
.
number
).
to
eq
1347
expect
(
pull_request
.
number
).
to
eq
1347
...
@@ -139,11 +158,11 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -139,11 +158,11 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
end
describe
'#valid?'
do
describe
'#valid?'
do
let
(
:invalid_branch
)
{
OpenStruct
.
new
(
ref:
'invalid-branch'
)
}
let
(
:invalid_branch
)
{
double
(
ref:
'invalid-branch'
).
as_null_object
}
context
'when source, and target repositories are the same'
do
context
'when source, and target repositories are the same'
do
context
'and source and target branches exists'
do
context
'and source and target branches exists'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
head:
source_branch
,
base:
target_branch
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
head:
source_branch
,
base:
target_branch
))
}
it
'returns true'
do
it
'returns true'
do
expect
(
pull_request
.
valid?
).
to
eq
true
expect
(
pull_request
.
valid?
).
to
eq
true
...
@@ -151,7 +170,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -151,7 +170,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
end
context
'and source branch doesn not exists'
do
context
'and source branch doesn not exists'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
head:
invalid_branch
,
base:
target_branch
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
head:
invalid_branch
,
base:
target_branch
))
}
it
'returns false'
do
it
'returns false'
do
expect
(
pull_request
.
valid?
).
to
eq
false
expect
(
pull_request
.
valid?
).
to
eq
false
...
@@ -159,7 +178,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -159,7 +178,7 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
end
context
'and target branch doesn not exists'
do
context
'and target branch doesn not exists'
do
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
.
merge
(
head:
source_branch
,
base:
invalid_branch
))
}
let
(
:raw_data
)
{
double
(
base_data
.
merge
(
head:
source_branch
,
base:
invalid_branch
))
}
it
'returns false'
do
it
'returns false'
do
expect
(
pull_request
.
valid?
).
to
eq
false
expect
(
pull_request
.
valid?
).
to
eq
false
...
@@ -168,8 +187,8 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -168,8 +187,8 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
end
context
'when source repo is a fork'
do
context
'when source repo is a fork'
do
let
(
:source_repo
)
{
OpenStruct
.
new
(
id:
2
,
fork:
true
)
}
let
(
:source_repo
)
{
double
(
id:
2
,
fork:
true
)
}
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
)
}
let
(
:raw_data
)
{
double
(
base_data
)
}
it
'returns false'
do
it
'returns false'
do
expect
(
pull_request
.
valid?
).
to
eq
false
expect
(
pull_request
.
valid?
).
to
eq
false
...
@@ -177,8 +196,8 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
...
@@ -177,8 +196,8 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
end
context
'when target repo is a fork'
do
context
'when target repo is a fork'
do
let
(
:target_repo
)
{
OpenStruct
.
new
(
id:
2
,
fork:
true
)
}
let
(
:target_repo
)
{
double
(
id:
2
,
fork:
true
)
}
let
(
:raw_data
)
{
OpenStruct
.
new
(
base_data
)
}
let
(
:raw_data
)
{
double
(
base_data
)
}
it
'returns false'
do
it
'returns false'
do
expect
(
pull_request
.
valid?
).
to
eq
false
expect
(
pull_request
.
valid?
).
to
eq
false
...
...
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