Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoBackendAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External 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
Dojo Project (HES-SO)
Projects
Backend
DojoBackendAPI
Commits
92126200
Commit
92126200
authored
2 years ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
Add GitlabHelper
parent
b3c524da
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ExpressAPI/src/helpers/GitlabHelper.ts
+71
-0
71 additions, 0 deletions
ExpressAPI/src/helpers/GitlabHelper.ts
with
71 additions
and
0 deletions
ExpressAPI/src/helpers/GitlabHelper.ts
0 → 100644
+
71
−
0
View file @
92126200
import
axios
from
'
axios
'
;
import
Config
from
'
../config/Config
'
;
import
GitlabRepository
from
'
../shared/types/Gitlab/GitlabRepository
'
;
import
GitlabAccessLevel
from
'
../shared/types/Gitlab/GitlabAccessLevel
'
;
import
GitlabMember
from
'
../shared/types/Gitlab/GitlabMember
'
;
enum
GitlabRoutes
{
REPOSITORY_GET
=
'
/projects/{{id}}
'
,
REPOSITORY_CREATE
=
'
/projects
'
,
REPOSITORY_MEMBER_ADD
=
'
/projects/{{id}}/members
'
,
REPOSITORY_MEMBERS_GET
=
'
/projects/{{id}}/members/all
'
}
class
GitlabHelper
{
private
static
_instance
:
GitlabHelper
;
private
constructor
()
{
}
public
static
get
instance
():
GitlabHelper
{
if
(
!
GitlabHelper
.
_instance
)
{
GitlabHelper
.
_instance
=
new
GitlabHelper
();
}
return
GitlabHelper
.
_instance
;
}
private
getApiUrl
(
route
:
GitlabRoutes
):
string
{
return
`
${
Config
.
gitlab
.
apiURL
}${
route
}
`
;
}
async
createRepository
(
name
:
string
,
description
:
string
,
visibility
:
string
,
initializeWithReadme
:
boolean
,
namespace
:
number
,
sharedRunnersEnabled
:
boolean
,
wikiEnabled
:
boolean
,
import_url
:
string
):
Promise
<
GitlabRepository
>
{
const
response
=
await
axios
.
post
<
GitlabRepository
>
(
this
.
getApiUrl
(
GitlabRoutes
.
REPOSITORY_CREATE
),
{
name
:
name
,
description
:
description
,
import_url
:
import_url
,
initialize_with_readme
:
initializeWithReadme
,
namespace_id
:
namespace
,
shared_runners_enabled
:
sharedRunnersEnabled
,
visibility
:
visibility
,
wiki_enabled
:
wikiEnabled
});
return
response
.
data
;
}
async
getRepository
(
idOrNamespace
:
string
):
Promise
<
GitlabRepository
>
{
const
response
=
await
axios
.
get
<
GitlabRepository
>
(
this
.
getApiUrl
(
GitlabRoutes
.
REPOSITORY_GET
).
replace
(
'
{{id}}
'
,
encodeURIComponent
(
idOrNamespace
)));
return
response
.
data
;
}
async
getRepositoryMembers
(
idOrNamespace
:
string
):
Promise
<
Array
<
GitlabMember
>>
{
const
response
=
await
axios
.
get
<
Array
<
GitlabMember
>>
(
this
.
getApiUrl
(
GitlabRoutes
.
REPOSITORY_MEMBERS_GET
).
replace
(
'
{{id}}
'
,
encodeURIComponent
(
idOrNamespace
)));
return
response
.
data
;
}
async
addRepositoryMember
(
repoId
:
number
,
userId
:
number
,
accessLevel
:
GitlabAccessLevel
):
Promise
<
GitlabMember
>
{
const
response
=
await
axios
.
post
<
GitlabMember
>
(
this
.
getApiUrl
(
GitlabRoutes
.
REPOSITORY_MEMBER_ADD
).
replace
(
'
{{id}}
'
,
String
(
repoId
)),
{
user_id
:
userId
,
access_level
:
accessLevel
});
return
response
.
data
;
}
}
export
default
GitlabHelper
.
instance
;
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