Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoCLI
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
UI
DojoCLI
Commits
83c73d2c
Commit
83c73d2c
authored
2 years ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
Add gitlab manager
parent
27947657
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
NodeApp/src/managers/GitlabManager.ts
+108
-0
108 additions, 0 deletions
NodeApp/src/managers/GitlabManager.ts
with
108 additions
and
0 deletions
NodeApp/src/managers/GitlabManager.ts
0 → 100644
+
108
−
0
View file @
83c73d2c
import
LocalConfig
from
'
../Config/LocalConfig/LocalConfig
'
;
import
LocalConfigKeys
from
'
../Config/LocalConfig/LocalConfigKeys
'
;
import
axios
from
'
axios
'
;
import
Config
from
'
../Config/Config
'
;
import
ora
from
'
ora
'
;
class
GitlabManager
{
private
_token
:
string
|
null
=
null
;
constructor
()
{
}
private
static
_instance
:
GitlabManager
;
public
static
get
instance
():
GitlabManager
{
if
(
!
GitlabManager
.
_instance
)
{
GitlabManager
.
_instance
=
new
GitlabManager
();
}
return
GitlabManager
.
_instance
;
}
get
isLogged
():
boolean
{
return
this
.
_token
!==
null
;
}
get
token
():
string
{
return
this
.
_token
||
''
;
}
set
token
(
token
:
string
)
{
this
.
_token
=
token
;
LocalConfig
.
updateConfig
(
LocalConfigKeys
.
GITLAB_PERSONAL_TOKEN
,
token
);
}
public
async
testToken
(
verbose
:
boolean
=
true
):
Promise
<
[
boolean
,
boolean
]
>
{
let
result
:
[
boolean
,
boolean
]
=
[
false
,
false
];
type
NotificationSettings
=
{
level
:
string
}
let
notificationSettings
:
NotificationSettings
=
{
level
:
'
error
'
};
// Test read access
{
const
spinnerRead
:
ora
.
Ora
=
ora
(
'
Read access
'
);
if
(
verbose
)
{
spinnerRead
.
start
();
}
try
{
notificationSettings
=
(
await
this
.
getNotificationSettings
()).
data
as
NotificationSettings
;
result
[
0
]
=
true
;
if
(
verbose
)
{
spinnerRead
.
succeed
();
}
}
catch
(
e
)
{
if
(
verbose
)
{
spinnerRead
.
fail
();
}
}
}
// Test write access
{
const
spinnerWrite
:
ora
.
Ora
=
ora
(
'
Write access
'
);
if
(
verbose
)
{
spinnerWrite
.
start
();
}
const
someLevelTypes
=
[
'
disabled
'
,
'
participating
'
];
try
{
const
oldSettings
=
notificationSettings
;
const
newSettings
=
{
level
:
someLevelTypes
[
someLevelTypes
[
0
]
==
oldSettings
.
level
?
1
:
0
]
};
await
this
.
setNotificationSettings
(
newSettings
);
await
this
.
setNotificationSettings
(
oldSettings
);
result
[
1
]
=
true
;
if
(
verbose
)
{
spinnerWrite
.
succeed
();
}
}
catch
(
e
)
{
if
(
verbose
)
{
spinnerWrite
.
fail
();
}
}
}
return
result
;
}
public
getNotificationSettings
()
{
return
axios
.
get
(
`
${
Config
.
gitlabApiURL
}
/notification_settings`
);
}
public
setNotificationSettings
(
newSettings
:
any
)
{
return
axios
.
put
(
`
${
Config
.
gitlabApiURL
}
/notification_settings`
,
{
params
:
new
URLSearchParams
(
newSettings
)
});
}
}
export
default
GitlabManager
.
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