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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
a818b3f5
Commit
a818b3f5
authored
May 03, 2017
by
Eric Eastwood
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add IssuableReferenceUtility, `foo/bar#123`
See
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1797
parent
39b48cdf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
150 additions
and
0 deletions
+150
-0
app/assets/javascripts/lib/utils/issuable_reference_utils.js
app/assets/javascripts/lib/utils/issuable_reference_utils.js
+56
-0
spec/javascripts/lib/utils/issuable_reference_utils_spec.js
spec/javascripts/lib/utils/issuable_reference_utils_spec.js
+94
-0
No files found.
app/assets/javascripts/lib/utils/issuable_reference_utils.js
0 → 100644
View file @
a818b3f5
const
ISSUABLE_REFERENCE_RE
=
/^
((?:[^\s/]
+
(?:\/(?!
#
))?)
*
)
#
(\d
+
)
$/i
;
function
getReferencePieces
(
partialReference
,
namespacePath
,
projectPath
)
{
const
[
,
fullNamespace
=
''
,
resultantIssue
,
]
=
partialReference
.
match
(
ISSUABLE_REFERENCE_RE
);
const
namespacePieces
=
fullNamespace
.
split
(
'
/
'
);
const
resultantNamespace
=
namespacePieces
.
length
>
1
?
namespacePieces
.
slice
(
0
,
-
1
).
join
(
'
/
'
)
:
namespacePath
;
const
resultantProject
=
namespacePieces
.
slice
(
-
1
)[
0
]
||
projectPath
;
return
{
namespace
:
resultantNamespace
,
project
:
resultantProject
,
issue
:
resultantIssue
,
};
}
function
assembleNecessaryIssuableReference
(
partialReference
,
currentNamespacePath
,
currentProjectPath
,
)
{
const
{
namespace
,
project
,
issue
,
}
=
getReferencePieces
(
partialReference
,
currentNamespacePath
,
currentProjectPath
);
let
necessaryReference
=
`#
${
issue
}
`
;
if
(
currentProjectPath
!==
project
)
{
necessaryReference
=
project
+
necessaryReference
;
}
if
(
currentNamespacePath
!==
namespace
)
{
necessaryReference
=
`
${
namespace
}
/
${
necessaryReference
}
`
;
}
return
necessaryReference
;
}
function
assembleFullIssuableReference
(
partialReference
,
currentNamespacePath
,
currentProjectPath
)
{
const
{
namespace
,
project
,
issue
,
}
=
getReferencePieces
(
partialReference
,
currentNamespacePath
,
currentProjectPath
);
return
`
${
namespace
}
/
${
project
}
#
${
issue
}
`
;
}
export
{
ISSUABLE_REFERENCE_RE
,
getReferencePieces
,
assembleNecessaryIssuableReference
,
assembleFullIssuableReference
,
};
spec/javascripts/lib/utils/issuable_reference_utils_spec.js
0 → 100644
View file @
a818b3f5
import
{
getReferencePieces
,
assembleNecessaryIssuableReference
,
assembleFullIssuableReference
,
}
from
'
~/lib/utils/issuable_reference_utils
'
;
describe
(
'
issuable_reference_utils
'
,
()
=>
{
describe
(
'
getReferencePieces
'
,
()
=>
{
it
(
'
should work with only issue number reference
'
,
()
=>
{
expect
(
getReferencePieces
(
'
#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
({
namespace
:
'
foo
'
,
project
:
'
bar
'
,
issue
:
'
111
'
,
});
});
it
(
'
should work with project and issue number reference
'
,
()
=>
{
expect
(
getReferencePieces
(
'
qux#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
({
namespace
:
'
foo
'
,
project
:
'
qux
'
,
issue
:
'
111
'
,
});
});
it
(
'
should work with full reference
'
,
()
=>
{
expect
(
getReferencePieces
(
'
foo/garply#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
({
namespace
:
'
foo
'
,
project
:
'
garply
'
,
issue
:
'
111
'
,
});
});
it
(
'
should work with sub-groups
'
,
()
=>
{
expect
(
getReferencePieces
(
'
some/with/sub/groups/other#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
({
namespace
:
'
some/with/sub/groups
'
,
project
:
'
other
'
,
issue
:
'
111
'
,
});
});
it
(
'
does not mangle other group references
'
,
()
=>
{
expect
(
getReferencePieces
(
'
some/other#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
({
namespace
:
'
some
'
,
project
:
'
other
'
,
issue
:
'
111
'
,
});
});
it
(
'
does not mangle other group even with partial match
'
,
()
=>
{
expect
(
getReferencePieces
(
'
bar/baz/fido#111
'
,
'
foo/bar/baz
'
,
'
garply
'
)).
toEqual
({
namespace
:
'
bar/baz
'
,
project
:
'
fido
'
,
issue
:
'
111
'
,
});
});
});
describe
(
'
assembleNecessaryIssuableReference
'
,
()
=>
{
it
(
'
should work with only issue number reference
'
,
()
=>
{
expect
(
assembleNecessaryIssuableReference
(
'
#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
(
'
#111
'
);
});
it
(
'
should work with project and issue number reference
'
,
()
=>
{
expect
(
assembleNecessaryIssuableReference
(
'
qux#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
(
'
qux#111
'
);
});
it
(
'
should work with full reference to current project
'
,
()
=>
{
expect
(
assembleNecessaryIssuableReference
(
'
foo/garply#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
(
'
garply#111
'
);
});
it
(
'
should work with sub-groups
'
,
()
=>
{
expect
(
assembleNecessaryIssuableReference
(
'
some/with/sub/groups/other#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
(
'
some/with/sub/groups/other#111
'
);
});
it
(
'
does not mangle other group references
'
,
()
=>
{
expect
(
assembleNecessaryIssuableReference
(
'
some/other#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
(
'
some/other#111
'
);
});
it
(
'
does not mangle other group even with partial match
'
,
()
=>
{
expect
(
assembleNecessaryIssuableReference
(
'
bar/baz/fido#111
'
,
'
foo/bar/baz
'
,
'
garply
'
)).
toEqual
(
'
bar/baz/fido#111
'
);
});
});
describe
(
'
assembleFullIssuableReference
'
,
()
=>
{
it
(
'
should work with only issue number reference
'
,
()
=>
{
expect
(
assembleFullIssuableReference
(
'
#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
(
'
foo/bar#111
'
);
});
it
(
'
should work with project and issue number reference
'
,
()
=>
{
expect
(
assembleFullIssuableReference
(
'
qux#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
(
'
foo/qux#111
'
);
});
it
(
'
should work with full reference
'
,
()
=>
{
expect
(
assembleFullIssuableReference
(
'
foo/garply#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
(
'
foo/garply#111
'
);
});
it
(
'
should work with sub-groups
'
,
()
=>
{
expect
(
assembleFullIssuableReference
(
'
some/with/sub/groups/other#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
(
'
some/with/sub/groups/other#111
'
);
});
it
(
'
does not mangle other group references
'
,
()
=>
{
expect
(
assembleFullIssuableReference
(
'
some/other#111
'
,
'
foo
'
,
'
bar
'
)).
toEqual
(
'
some/other#111
'
);
});
it
(
'
does not mangle other group even with partial match
'
,
()
=>
{
expect
(
assembleFullIssuableReference
(
'
bar/baz/fido#111
'
,
'
foo/bar/baz
'
,
'
garply
'
)).
toEqual
(
'
bar/baz/fido#111
'
);
});
});
});
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