mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-15 15:10:31 -08:00
feat: pass branch info to git-sync
This commit is contained in:
parent
d593228887
commit
73bab6410e
6 changed files with 23 additions and 4 deletions
|
|
@ -113,8 +113,10 @@
|
|||
"LogoutGithubAccount": "登出Github账号",
|
||||
"LoginGithubAccount": "登录Github账号",
|
||||
"GitToken": "Git Token",
|
||||
"GitDefaultBranch": "Git默认分支",
|
||||
"GitRepoUrl": "Git仓库线上网址",
|
||||
"GitTokenDescription": "用于登录Git的凭证,一定时间后会过期",
|
||||
"GitDefaultBranchDescription": "你的Git的默认分支,Github在黑命贵事件后将其从master改为了main",
|
||||
"GitEmailDescription": "用于Git提交记录的Email,用于在Github等服务上统计每日提交量",
|
||||
"GitUserNameDescription": "用于登录Git的账户名,注意是你的仓库网址中你的名字部分",
|
||||
"SwitchCreateNewOrOpenExisted": "切换创建新的还是打开现有的WIKI",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { TextField, Button } from '@material-ui/core';
|
|||
import { SupportedStorageServices } from '@services/types';
|
||||
import { useUserInfoObservable } from '@services/auth/hooks';
|
||||
import { useAuth } from './gitTokenHooks';
|
||||
import { getServiceEmailTypes, getServiceTokenTypes, getServiceUserNameTypes } from '@services/auth/interface';
|
||||
import { getServiceBranchTypes, getServiceEmailTypes, getServiceTokenTypes, getServiceUserNameTypes } from '@services/auth/interface';
|
||||
|
||||
const AuthingLoginButton = styled(Button)`
|
||||
width: 100%;
|
||||
|
|
@ -54,6 +54,13 @@ export function GitTokenForm(props: {
|
|||
}}
|
||||
value={userInfo[getServiceEmailTypes(storageService)] ?? ''}
|
||||
/>
|
||||
<GitTokenInput
|
||||
helperText={t('AddWorkspace.GitDefaultBranchDescription')}
|
||||
onChange={(event) => {
|
||||
void window.service.auth.set(`${storageService}-branch`, event.target.value);
|
||||
}}
|
||||
value={userInfo[getServiceBranchTypes(storageService)] ?? ''}
|
||||
/>
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { debounce } from 'lodash';
|
|||
import { injectable } from 'inversify';
|
||||
import settings from 'electron-settings';
|
||||
import { IAuthingUserInfo, SupportedStorageServices } from '@services/types';
|
||||
import { IAuthenticationService, IUserInfos, ServiceEmailTypes, ServiceTokenTypes, ServiceUserNameTypes } from './interface';
|
||||
import { IAuthenticationService, IUserInfos, ServiceBranchTypes, ServiceEmailTypes, ServiceTokenTypes, ServiceUserNameTypes } from './interface';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { IGitUserInfos } from '@services/git/interface';
|
||||
|
||||
|
|
@ -32,11 +32,13 @@ export class Authentication implements IAuthenticationService {
|
|||
const gitUserName = await this.get((serviceName + '-userName') as ServiceUserNameTypes);
|
||||
const email = await this.get((serviceName + '-email') as ServiceEmailTypes);
|
||||
const accessToken = await this.get((serviceName + '-token') as ServiceTokenTypes);
|
||||
const branch = (await this.get((serviceName + '-branch') as ServiceBranchTypes)) ?? 'main';
|
||||
if (gitUserName !== undefined && accessToken !== undefined) {
|
||||
return {
|
||||
gitUserName,
|
||||
email,
|
||||
accessToken,
|
||||
branch,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -60,7 +62,7 @@ export class Authentication implements IAuthenticationService {
|
|||
};
|
||||
|
||||
private sanitizeUserInfo(info: Partial<IUserInfos>): Partial<IUserInfos> {
|
||||
return info;
|
||||
return { ...info, 'github-branch': info['github-branch'] ?? 'main' };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -20,12 +20,18 @@ export const getServiceEmailTypes = (serviceType: SupportedStorageServices): Ser
|
|||
/** Git push: Git commit message email, you may use different email for different storage service */
|
||||
type EmailRecord = Record<ServiceEmailTypes, string>;
|
||||
|
||||
export type ServiceBranchTypes = `${SupportedStorageServices}-branch`;
|
||||
export const getServiceBranchTypes = (serviceType: SupportedStorageServices): ServiceBranchTypes => `${serviceType}-branch`;
|
||||
/** Git push: Git commit message branch, you may use different branch for different storage service */
|
||||
type BranchRecord = Record<ServiceBranchTypes, string>;
|
||||
|
||||
export type IUserInfos = {
|
||||
/** Default UserName in TiddlyWiki, each wiki can have different username, but fallback to this if not specific on */
|
||||
userName: string;
|
||||
} & Partial<TokenRecord> &
|
||||
Partial<UserNameRecord> &
|
||||
Partial<EmailRecord>;
|
||||
Partial<EmailRecord> &
|
||||
Partial<BranchRecord>;
|
||||
|
||||
/**
|
||||
* Handle login to Github GitLab Coding.net
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
export const defaultGitInfo = {
|
||||
email: 'tiddlygit@gmail.com',
|
||||
gitUserName: 'tidgi',
|
||||
branch: 'main',
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { ModifiedFileList } from 'git-sync-js';
|
|||
export interface IGitUserInfos extends IGitUserInfosWithoutToken {
|
||||
/** Github Login: token */
|
||||
accessToken: string;
|
||||
branch: string;
|
||||
}
|
||||
|
||||
export interface IGitUserInfosWithoutToken {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue