-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): Add version controls settings (WIP) (#6036)
* feat(editor): Version control paywall (WIP) * fix(editor): remove version control docs link * feat(editor): Adding version control settings (WIP) * feat(editor): Adding version control settings (WIP) * fix(editor): use rest api root path in version control * fix(editor): adding preferences * fix(editor): adding preferences * fix(editor): change store action name
- Loading branch information
Showing
8 changed files
with
358 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { IRestApiContext, VersionControlPreferences } from '@/Interface'; | ||
import { makeRestApiRequest } from '@/utils'; | ||
import type { IDataObject } from 'n8n-workflow'; | ||
|
||
const versionControlApiRoot = '/version-control'; | ||
|
||
export const initSsh = (context: IRestApiContext, data: IDataObject): Promise<string> => { | ||
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/init-ssh`, data); | ||
}; | ||
|
||
export const initRepository = ( | ||
context: IRestApiContext, | ||
): Promise<{ branches: string[]; currentBranch: string }> => { | ||
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/init-repository`); | ||
}; | ||
|
||
export const sync = (context: IRestApiContext, data: IDataObject): Promise<void> => { | ||
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/push`, data); | ||
}; | ||
|
||
export const getConfig = ( | ||
context: IRestApiContext, | ||
): Promise<{ remoteRepository: string; name: string; email: string; currentBranch: string }> => { | ||
return makeRestApiRequest(context, 'GET', `${versionControlApiRoot}/config`); | ||
}; | ||
|
||
export const setPreferences = ( | ||
context: IRestApiContext, | ||
preferences: Partial<VersionControlPreferences>, | ||
): Promise<VersionControlPreferences> => { | ||
return makeRestApiRequest(context, 'POST', `${versionControlApiRoot}/preferences`, preferences); | ||
}; | ||
|
||
export const getPreferences = (context: IRestApiContext): Promise<VersionControlPreferences> => { | ||
return makeRestApiRequest(context, 'GET', `${versionControlApiRoot}/preferences`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1286,6 +1286,24 @@ | |
"settings.versionControl.actionBox.title": "Available on Enterprise plan", | ||
"settings.versionControl.actionBox.description": "Use Version Control to connect your instance to an external Git repository to backup and track changes made to your workflows, variables, and credentials. With Version Control you can also sync instances across multiple environments (development, production...).", | ||
"settings.versionControl.actionBox.buttonText": "See plans", | ||
"settings.versionControl.description": "Versioning allows you to connect your n8n instance to a Git branch of a repository. You can connect your branches to multiples n8n instances to create a multi environments setup. Learn how to set up versioning and environments in n8n.", | ||
"settings.versionControl.repoUrl": "Git repository URL", | ||
"settings.versionControl.repoUrlPlaceholder": "e.g. [email protected]:my-team/my-repository", | ||
"settings.versionControl.repoUrlDescription": "The SSH url of your Git repository", | ||
"settings.versionControl.authorName": "Author name", | ||
"settings.versionControl.authorEmail": "Author email", | ||
"settings.versionControl.sshKey": "SSH Key", | ||
"settings.versionControl.sshKeyDescription": "Paste the SSH key in yout git repository settings. {link}.", | ||
"settings.versionControl.sshKeyDescriptionLink": "More info.", | ||
"settings.versionControl.button.continue": "Continue", | ||
"settings.versionControl.button.connect": "Connect", | ||
"settings.versionControl.branches": "Select branch", | ||
"settings.versionControl.switchBranch.title": "Switch to {branch} branch", | ||
"settings.versionControl.switchBranch.description": "Please confirm you want to switch the current n8n instance to the branch: {branch}", | ||
"settings.versionControl.sync.prompt.title": "Sync changes in {branch} branch", | ||
"settings.versionControl.sync.prompt.description": "All the changes on your n8n instances will be synced with branch {branch} on the remote git repository. The following git sequence will be executed: pull > commit > push.", | ||
"settings.versionControl.sync.prompt.placeholder": "Commit message", | ||
"settings.versionControl.sync.prompt.error": "Please enter a commit message", | ||
"showMessage.cancel": "@:_reusableBaseText.cancel", | ||
"showMessage.ok": "OK", | ||
"showMessage.showDetails": "Show Details", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,88 @@ | ||
import { computed } from 'vue'; | ||
import { computed, reactive } from 'vue'; | ||
import { defineStore } from 'pinia'; | ||
import type { IDataObject } from 'n8n-workflow'; | ||
import { EnterpriseEditionFeature } from '@/constants'; | ||
import { useSettingsStore } from '@/stores/settings'; | ||
import * as vcApi from '@/api/versionControl'; | ||
import { useRootStore } from '@/stores/n8nRootStore'; | ||
import type { VersionControlPreferences } from '@/Interface'; | ||
|
||
export const useVersionControlStore = defineStore('versionControl', () => { | ||
const rootStore = useRootStore(); | ||
const settingsStore = useSettingsStore(); | ||
|
||
const isEnterpriseVersionControlEnabled = computed(() => | ||
settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.VersionControl), | ||
); | ||
|
||
const preferences = reactive<VersionControlPreferences>({ | ||
branchName: '', | ||
authorName: '', | ||
authorEmail: '', | ||
repositoryUrl: '', | ||
branchReadOnly: false, | ||
branchColor: '#000000', | ||
connected: false, | ||
publicKey: '', | ||
}); | ||
|
||
const state = reactive({ | ||
branches: [] as string[], | ||
currentBranch: '', | ||
authorName: '', | ||
authorEmail: '', | ||
repositoryUrl: '', | ||
sshKey: '', | ||
commitMessage: 'commit message', | ||
}); | ||
|
||
const initSsh = async (data: IDataObject) => { | ||
state.sshKey = await vcApi.initSsh(rootStore.getRestApiContext, data); | ||
}; | ||
|
||
const initRepository = async () => { | ||
const { branches, currentBranch } = await vcApi.initRepository(rootStore.getRestApiContext); | ||
state.branches = branches; | ||
state.currentBranch = currentBranch; | ||
}; | ||
|
||
const sync = async (data: { commitMessage: string }) => { | ||
state.commitMessage = data.commitMessage; | ||
return vcApi.sync(rootStore.getRestApiContext, { message: data.commitMessage }); | ||
}; | ||
const getConfig = async () => { | ||
const { remoteRepository, name, email, currentBranch } = await vcApi.getConfig( | ||
rootStore.getRestApiContext, | ||
); | ||
state.repositoryUrl = remoteRepository; | ||
state.authorName = name; | ||
state.authorEmail = email; | ||
state.currentBranch = currentBranch; | ||
}; | ||
|
||
const setPreferences = (data: Partial<VersionControlPreferences>) => { | ||
Object.assign(preferences, data); | ||
}; | ||
|
||
const getPreferences = async () => { | ||
const data = await vcApi.getPreferences(rootStore.getRestApiContext); | ||
setPreferences(data); | ||
}; | ||
|
||
const savePreferences = async (preferences: Partial<VersionControlPreferences>) => { | ||
const data = await vcApi.setPreferences(rootStore.getRestApiContext, preferences); | ||
setPreferences(data); | ||
}; | ||
|
||
return { | ||
isEnterpriseVersionControlEnabled, | ||
state, | ||
initSsh, | ||
initRepository, | ||
sync, | ||
getConfig, | ||
getPreferences, | ||
setPreferences, | ||
savePreferences, | ||
}; | ||
}); |
Oops, something went wrong.