Skip to content

Commit 3148ba6

Browse files
committed
support gitlab repo
1 parent 9d38fbe commit 3148ba6

File tree

5 files changed

+125
-1
lines changed

5 files changed

+125
-1
lines changed

apps/remix-ide/src/app/tabs/locales/en/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"settings.gitAccessTokenTitle": "Github Credentials",
1515
"settings.gitAccessTokenText": "The access token is used to publish a Gist and retrieve GitHub contents. You may need to input username/email.",
1616
"settings.gitAccessTokenText2":"Go to github token page (link below) to create a new token and save it in Remix. Make sure this token has only 'create gist' permission",
17+
"settings.gitlabTokenTitle": "Gitlab Credentials",
18+
"settings.gitlabTokenText": "The access token is used to retrieve GitLab contents. You may need to input username/email.",
19+
"settings.gitlabTokenText2":"Go to gitlab token page (link below) to create a new token and save it in Remix.",
1720
"settings.etherscanTokenTitle": "EtherScan Access Token",
1821
"settings.etherscanAccessTokenText": "Manage the api key used to interact with Etherscan.",
1922
"settings.etherscanAccessTokenText2": "Go to Etherscan api key page (link below) to create a new api key and save it in Remix.",

libs/remix-ui/settings/src/lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const textSecondary = 'text-secondary'
22
export const textDark = 'text-dark'
33

44
export const gitAccessTokenLink = 'https://github.com/settings/tokens/new?scopes=gist,repo&description=Remix%20IDE%20Token'
5+
export const gitlabTokenLink = 'https://gitlab.com/-/user_settings/personal_access_tokens'
56
export const etherscanTokenLink = 'https://etherscan.io/myapikey'
67
export const labels = {
78
'gist': {
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import {CopyToClipboard} from '@remix-ui/clipboard'
2+
import {CustomTooltip} from '@remix-ui/helper'
3+
import React, {useEffect, useState} from 'react'
4+
import {FormattedMessage, useIntl} from 'react-intl'
5+
import {GithubSettingsProps} from '../types'
6+
import {gitlabTokenLink} from './constants'
7+
8+
export function GitlabSettings(props: GithubSettingsProps) {
9+
const [gitlabToken, setGitlabToken] = useState<string>('')
10+
const [gitlabUserName, setGitlabUsername] = useState<string>('')
11+
const [gitlabEmail, setGitlabEmail] = useState<string>('')
12+
const intl = useIntl()
13+
14+
useEffect(() => {
15+
if (props.config) {
16+
const gitlabToken = props.config.get('settings/gitlab-token') || ''
17+
const gitlabUserName = props.config.get('settings/gitlab-user-name') || ''
18+
const gitlabEmail = props.config.get('settings/gitlab-email') || ''
19+
20+
setGitlabToken(gitlabToken)
21+
setGitlabUsername(gitlabUserName)
22+
setGitlabEmail(gitlabEmail)
23+
}
24+
}, [props.config])
25+
26+
const handleChangeTokenState = (event) => {
27+
const token = event.target.value ? event.target.value.trim() : event.target.value
28+
setGitlabToken(token)
29+
}
30+
31+
const handleChangeUserNameState = (event) => {
32+
setGitlabUsername(event.target.value)
33+
}
34+
35+
const handleChangeEmailState = (event) => {
36+
setGitlabEmail(event.target.value)
37+
}
38+
39+
// api key settings
40+
const saveGitlabToken = () => {
41+
props.saveToken(gitlabToken, gitlabUserName, gitlabEmail)
42+
}
43+
44+
const removeToken = () => {
45+
setGitlabToken('')
46+
setGitlabUsername('')
47+
setGitlabEmail('')
48+
props.removeToken()
49+
}
50+
51+
return (
52+
<div className="border-top">
53+
<div className="card-body pt-3 pb-2">
54+
<h6 className="card-title">
55+
<FormattedMessage id="settings.gitlabTokenTitle" />
56+
</h6>
57+
<p className="mb-1">
58+
<FormattedMessage id="settings.gitlabTokenText" />
59+
</p>
60+
<p className="">
61+
<FormattedMessage id="settings.gitlabTokenText2" />
62+
</p>
63+
<p className="mb-1">
64+
<a className="text-primary" target="_blank" href={gitlabTokenLink}>
65+
{gitlabTokenLink}
66+
</a>
67+
</p>
68+
<div>
69+
<label className="mb-0 pb-0">
70+
<FormattedMessage id="settings.token" />:
71+
</label>
72+
<div className="input-group text-secondary mb-0 h6">
73+
<input id="gitlabtoken" data-id="settingsTabGitlabToken" type="password" className="form-control" onChange={(e) => handleChangeTokenState(e)} value={gitlabToken} />
74+
<div className="input-group-append">
75+
<CopyToClipboard tip={intl.formatMessage({id: 'settings.copy'})} content={gitlabToken} data-id="copyToClipboardCopyIcon" className="far fa-copy ml-1 p-2 mt-1" direction={'top'} />
76+
</div>
77+
</div>
78+
</div>
79+
<div>
80+
<label className="pt-2 mb-0 pb-0">
81+
<FormattedMessage id="settings.username" />:
82+
</label>
83+
<div className="text-secondary mb-0 h6">
84+
<input id="gitlabusername" data-id="settingsTabGitlabUsername" type="text" className="form-control" onChange={(e) => handleChangeUserNameState(e)} value={gitlabUserName} />
85+
</div>
86+
</div>
87+
<div>
88+
<label className="pt-2 mb-0 pb-0">
89+
<FormattedMessage id="settings.email" />:
90+
</label>
91+
<div className="text-secondary mb-0 h6">
92+
<input id="gitlabemail" data-id="settingsTabGitlabEmail" type="text" className="form-control" onChange={(e) => handleChangeEmailState(e)} value={gitlabEmail} />
93+
<div className="d-flex justify-content-end pt-2">
94+
<input className="btn btn-sm btn-primary ml-2" id="savegitlabtoken" data-id="settingsTabSaveGitlabToken" onClick={saveGitlabToken} value={intl.formatMessage({id: 'settings.save'})} type="button"></input>
95+
<CustomTooltip tooltipText={<FormattedMessage id="settings.deleteGitlabCredentials" />} tooltipClasses="text-nowrap" tooltipId="removegitlabtokenTooltip" placement="top-start">
96+
<button className="btn btn-sm btn-secondary ml-2" id="removegitlabtoken" data-id="settingsTabRemoveGitlabToken" onClick={removeToken}>
97+
<FormattedMessage id="settings.remove" />
98+
</button>
99+
</CustomTooltip>
100+
</div>
101+
</div>
102+
</div>
103+
</div>
104+
</div>
105+
)
106+
}

libs/remix-ui/settings/src/lib/remix-ui-settings.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {RemixUiThemeModule, ThemeModule} from '@remix-ui/theme-module'
2727
import {RemixUiLocaleModule, LocaleModule} from '@remix-ui/locale-module'
2828
import {FormattedMessage, useIntl} from 'react-intl'
2929
import {GithubSettings} from './github-settings'
30+
import {GitlabSettings} from './gitlab-settings'
3031
import {EtherscanSettings} from './etherscan-settings'
3132

3233
/* eslint-disable-next-line */
@@ -590,6 +591,19 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
590591
}}
591592
config={props.config}
592593
/>
594+
<GitlabSettings
595+
saveToken={(gitlabToken: string, gitlabUserName: string, gitlabEmail: string) => {
596+
saveTokenToast(props.config, dispatchToast, gitlabToken, 'gitlab-token')
597+
saveTokenToast(props.config, dispatchToast, gitlabUserName, 'gitlab-user-name')
598+
saveTokenToast(props.config, dispatchToast, gitlabEmail, 'gitlab-email')
599+
}}
600+
removeToken={() => {
601+
removeTokenToast(props.config, dispatchToast, 'gitlab-token')
602+
removeTokenToast(props.config, dispatchToast, 'gitlab-user-name')
603+
removeTokenToast(props.config, dispatchToast, 'gitlab-email')
604+
}}
605+
config={props.config}
606+
/>
593607
<EtherscanSettings
594608
saveToken={(etherscanToken: string) => {
595609
saveTokenToast(props.config, dispatchToast, etherscanToken, 'etherscan-access-token')

libs/remix-ui/workspace/src/lib/actions/workspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ export const getWorkspaces = async (): Promise<{ name: string; isGitRepo: boolea
606606

607607
export const cloneRepository = async (url: string) => {
608608
const config = plugin.registry.get('config').api
609-
const token = config.get('settings/gist-access-token')
609+
const token = config.get(`settings/${url.startsWith('https://github.com')? 'gist-access-token' : 'gitlab-token'}`)
610610
const repoConfig = { url, token }
611611

612612
if (plugin.registry.get('platform').api.isDesktop()) {

0 commit comments

Comments
 (0)