Skip to content

Commit

Permalink
mhutchie#462 Removed CI/CD column
Browse files Browse the repository at this point in the history
  • Loading branch information
keydepth committed May 2, 2021
1 parent 2dc18ad commit beec767
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 95 deletions.
76 changes: 10 additions & 66 deletions src/cicdManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ export class CicdManager extends Disposable {
private githubTimeout: number = 0;
private gitLabTimeout: number = 0;
private jenkinsTimeout: number = 0;
private initialState: boolean = true;
private requestPage: number = -1;
private requestPageTimeout: NodeJS.Timer | null = null;
private cicdConfigsPrev: CICDConfig[] = [];

private per_page: number = 100;

Expand Down Expand Up @@ -77,75 +73,23 @@ export class CicdManager extends Disposable {
}

/**
* Fetch an cicd, either from the cache if it already exists, or queue it to be fetched.
* Get the data of an cicd.
* @param repo The repository that the cicd is used in.
* @param hash The hash identifying the cicd commit.
* @param cicdConfigs The CICDConfigs.
* @returns A JSON encoded data of an cicd if the cicd exists, otherwise NULL.
*/
public fetchCICDStatus(repo: string, hash: string) {
if (typeof this.cicds[repo] !== 'undefined' && typeof this.cicds[repo][hash] !== 'undefined') {
// CICD exists in the cache
this.emitCICD(repo, hash, this.cicds[repo][hash]);
} else {

public getCICDDetail(repo: string, hash: string) {
return new Promise<string | null>((resolve) => {
let repos = this.repoManager.getRepos();
if (typeof repos[repo] !== 'undefined') {
if (repos[repo].cicdConfigs !== null) {
let cicdConfigs = repos[repo].cicdConfigs;
if (cicdConfigs !== null) {
// Check update user config
const cicdConfigsJSON = JSON.stringify(Object.entries(cicdConfigs).sort());
const cicdConfigsPrevJSON = JSON.stringify(Object.entries(this.cicdConfigsPrev).sort());
if (cicdConfigsJSON !== cicdConfigsPrevJSON) {
this.initialState = true;
this.requestPage = -1;
if (this.requestPageTimeout !== null) {
clearTimeout(this.requestPageTimeout);
}
this.requestPageTimeout = null;
}
// Deep Clone cicdConfigs
this.cicdConfigsPrev = JSON.parse(JSON.stringify(cicdConfigs));
// CICD not in the cache, request it
if (this.initialState) {
this.initialState = false;
cicdConfigs.forEach(cicdConfig => {
this.queue.add(repo, cicdConfig, this.requestPage, true);
});
// Reset initial state for 10 seconds
setTimeout(() => {
this.logger.log('Reset initial timer of CICD');
this.initialState = true;
}, 10000);
// set request page to top
this.requestPage = 1;
// Reset request page to all after 10 minutes
if (this.requestPageTimeout === null) {
this.requestPageTimeout = setTimeout(() => {
this.logger.log('Reset request page of CICD');
this.requestPage = -1;
this.requestPageTimeout = null;
}, 600000);
}
}
}
let cicdConfigs = repos[repo].cicdConfigs;
if (cicdConfigs !== null) {
cicdConfigs.forEach(cicdConfig => {
this.queue.add(repo, cicdConfig, -1, true, true, hash);
});
}
}
}
}

/**
* Get the data of an cicd.
* @param repo The repository that the cicd is used in.
* @param hash The hash identifying the cicd commit.
* @param cicdConfigs The CICDConfigs.
* @returns A JSON encoded data of an cicd if the cicd exists, otherwise NULL.
*/
public getCICDDetail(repo: string, hash: string, cicdConfigs: CICDConfig[]) {
return new Promise<string | null>((resolve) => {
cicdConfigs.forEach(cicdConfig => {
this.queue.add(repo, cicdConfig, -1, true, true, hash);
});
if (typeof this.cicds[repo] !== 'undefined' && typeof this.cicds[repo][hash] !== 'undefined' && this.cicds[repo][hash] !== null) {
resolve(JSON.stringify(this.cicds[repo][hash]));
} else {
Expand Down Expand Up @@ -261,7 +205,7 @@ export class CicdManager extends Disposable {
if (res.headers['x-ratelimit-remaining'] === '0') {
// If the GitHub Api rate limit was reached, store the github timeout to prevent subsequent requests
this.githubTimeout = parseInt(<string>res.headers['x-ratelimit-reset']) * 1000;
this.logger.log('GitHub API Rate Limit Reached - Paused fetching from GitLab until the Rate Limit is reset (RateLimit=' + res.headers['x-ratelimit-limit'] + '(1 hour)/' + new Date(this.githubTimeout).toString() + ')');
this.logger.log('GitHub API Rate Limit Reached - Paused fetching from GitHub until the Rate Limit is reset (RateLimit=' + res.headers['x-ratelimit-limit'] + '(1 hour)/' + new Date(this.githubTimeout).toString() + ')');
if (cicdRequest.cicdConfig.cicdToken === '') {
this.logger.log('GitHub API Rate Limit can upgrade by Access Token.');
}
Expand Down
6 changes: 2 additions & 4 deletions src/extensionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ export class ExtensionState extends Disposable {
let config: CICDConfig = {
provider: element.provider,
cicdUrl: element.cicdUrl,
cicdToken: decrypted.toString(),
custom: null
cicdToken: decrypted.toString()
};
outputSet[repo].cicdConfigs?.push(config);
}
Expand Down Expand Up @@ -180,8 +179,7 @@ export class ExtensionState extends Disposable {
let config: CICDConfig = {
provider: cicdConfig.provider,
cicdUrl: cicdConfig.cicdUrl,
cicdToken: iv.toString('hex') + ':' + encrypted.toString('hex'),
custom: null
cicdToken: iv.toString('hex') + ':' + encrypted.toString('hex')
};
cicdConfigsEncrypto.push(config);
});
Expand Down
5 changes: 1 addition & 4 deletions src/gitGraphView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class GitGraphView extends Disposable {
? this.dataSource.getCommitDetails(msg.repo, msg.commitHash, msg.hasParents)
: this.dataSource.getStashDetails(msg.repo, msg.commitHash, msg.stash),
msg.avatarEmail !== null ? this.avatarManager.getAvatarImage(msg.avatarEmail) : Promise.resolve(null),
msg.cicdConfigs !== null ? this.cicdManager.getCICDDetail(msg.repo, msg.commitHash, msg.cicdConfigs) : Promise.resolve(null)
this.cicdManager.getCICDDetail(msg.repo, msg.commitHash)
]);
this.sendMessage({
command: 'commitDetails',
Expand Down Expand Up @@ -407,9 +407,6 @@ export class GitGraphView extends Disposable {
case 'fetchAvatar':
this.avatarManager.fetchAvatarImage(msg.email, msg.repo, msg.remote, msg.commits);
break;
case 'fetchCICD':
this.cicdManager.fetchCICDStatus(msg.repo, msg.hash);
break;
case 'fetchIntoLocalBranch':
this.sendMessage({
command: 'fetchIntoLocalBranch',
Expand Down
11 changes: 1 addition & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,10 @@ export const enum CICDProvider {

interface CICDConfigBuiltIn extends CICDConfigBase {
readonly provider: CICDProvider;
readonly custom: null;
}

interface CICDConfigCustom extends CICDConfigBase {
readonly provider: CICDProvider.Custom;
readonly custom: {
readonly name: string,
readonly templateUrl: string
};
}

export type CICDConfig = CICDConfigBuiltIn | CICDConfigCustom;
export type CICDConfig = CICDConfigBuiltIn;

export interface GitRepoState {
cdvDivider: number;
Expand Down Expand Up @@ -718,7 +710,6 @@ export interface RequestCommitDetails extends RepoRequest {
readonly stash: GitCommitStash | null; // null => request is for a commit, otherwise => request is for a stash
readonly avatarEmail: string | null; // string => fetch avatar with the given email, null => don't fetch avatar
readonly refresh: boolean;
readonly cicdConfigs: CICDConfig[] | null;
}
export interface ResponseCommitDetails extends ResponseWithErrorInfo {
readonly command: 'commitDetails';
Expand Down
12 changes: 5 additions & 7 deletions tests/gitGraphView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ describe('GitGraphView', () => {
logger = new Logger();
dataSource = new DataSource({ path: '/path/to/git', version: '2.25.0' }, onDidChangeConfiguration.subscribe, onDidChangeGitExecutable.subscribe, logger);
extensionState = new ExtensionState(vscode.mocks.extensionContext, onDidChangeGitExecutable.subscribe);
jest.spyOn(extensionState, 'getCICDCache').mockReturnValue({});
avatarManager = new AvatarManager(dataSource, extensionState, logger);
cicdManager = new CicdManager(extensionState, repoManager, logger);
repoManager = new RepoManager(dataSource, extensionState, onDidChangeConfiguration.subscribe, logger);
cicdManager = new CicdManager(extensionState, repoManager, logger);

spyOnLog = jest.spyOn(logger, 'log');
spyOnLogError = jest.spyOn(logger, 'logError');
Expand Down Expand Up @@ -966,8 +967,7 @@ describe('GitGraphView', () => {
hasParents: true,
stash: null,
avatarEmail: '[email protected]',
refresh: false,
cicdConfigs: null
refresh: false
});

// Assert
Expand Down Expand Up @@ -1005,8 +1005,7 @@ describe('GitGraphView', () => {
hasParents: true,
stash: null,
avatarEmail: null,
refresh: false,
cicdConfigs: null
refresh: false
});

// Assert
Expand Down Expand Up @@ -1051,8 +1050,7 @@ describe('GitGraphView', () => {
hasParents: true,
stash: stash,
avatarEmail: null,
refresh: false,
cicdConfigs: null
refresh: false
});

// Assert
Expand Down
3 changes: 1 addition & 2 deletions web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,7 @@ class GitGraphView {
hasParents: commit.parents.length > 0,
stash: commit.stash,
avatarEmail: this.config.fetchAvatars && hash !== UNCOMMITTED ? commit.email : null,
refresh: refresh,
cicdConfigs: this.gitRepos[this.currentRepo].cicdConfigs
refresh: refresh
});
}

Expand Down
3 changes: 1 addition & 2 deletions web/settingsWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ class SettingsWidget {
const updateConfigWithFormValues = (values: DialogInputValue[]) => {
let config: GG.CICDConfig = {
provider: <GG.CICDProvider>parseInt(<string>values[0]), cicdUrl: <string>values[1],
cicdToken: <string>values[2],
custom: null
cicdToken: <string>values[2]
};
return config;
};
Expand Down

0 comments on commit beec767

Please sign in to comment.