mirror of
https://github.com/bendtherules/github-delete-unused-repos.git
synced 2026-08-18 13:52:59 +00:00
Rename + Actually push redux filter states
This commit is contained in:
@@ -2,7 +2,26 @@ import * as Octokit from '@octokit/rest';
|
|||||||
import assert = require('assert');
|
import assert = require('assert');
|
||||||
import Bottleneck from 'bottleneck';
|
import Bottleneck from 'bottleneck';
|
||||||
|
|
||||||
import { OctokitMod, ResponseWithDataArray, RepoFromGetUserRepo, ResponseFromGetUserRepo, RepoNameWithBranchesAndParent, RepoNameWithUnusedFlag, ObjectWithPerPage, ResponseWithDataArrayAndMeta, RepoNameWithBranches, BranchFromGetBranches, ResponseFromGetBranches, RepoNameWithParentRepo, ResponseFromGetRepo, ResponseFromCompareCommits, OwnerFromGetContributors, ResponseFromGetContributors } from './types';
|
import {
|
||||||
|
OctokitMod,
|
||||||
|
ResponseWithDataArray,
|
||||||
|
RepoFromGetUserRepo,
|
||||||
|
ResponseFromGetUserRepo,
|
||||||
|
RepoNameWithBranchesAndParent,
|
||||||
|
RepoNameWithUnusedFlag,
|
||||||
|
ObjectWithPerPage,
|
||||||
|
ResponseWithDataArrayAndMeta,
|
||||||
|
RepoNameWithBranches,
|
||||||
|
BranchFromGetBranches,
|
||||||
|
ResponseFromGetBranches,
|
||||||
|
RepoNameWithParentRepo,
|
||||||
|
ResponseFromGetRepo,
|
||||||
|
ResponseFromCompareCommits,
|
||||||
|
OwnerFromGetContributors,
|
||||||
|
ResponseFromGetContributors,
|
||||||
|
} from './types';
|
||||||
|
import { createAppStore, ActionsType, ApplicationState, ActionNames, FilterSteps, FilterStatus } from './store';
|
||||||
|
import { Store } from 'redux';
|
||||||
|
|
||||||
// +++ General init +++
|
// +++ General init +++
|
||||||
const octokit = new Octokit() as OctokitMod;
|
const octokit = new Octokit() as OctokitMod;
|
||||||
@@ -24,12 +43,21 @@ octokit.authenticate({
|
|||||||
});
|
});
|
||||||
// --- End General init ---
|
// --- End General init ---
|
||||||
|
|
||||||
|
|
||||||
class GithubDetectUnusedRepos {
|
class GithubDetectUnusedRepos {
|
||||||
private username: string;
|
private username: string;
|
||||||
|
reduxStore: Store<ApplicationState, ActionsType>;
|
||||||
|
|
||||||
constructor(username: string) {
|
constructor(username: string) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
|
this.reduxStore = createAppStore();
|
||||||
|
|
||||||
|
// Update username in redux store
|
||||||
|
this.reduxStore.dispatch({
|
||||||
|
type: ActionNames.InitUserName,
|
||||||
|
payload: {
|
||||||
|
userName: username
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchUnusedForkedRepos() {
|
public async fetchUnusedForkedRepos() {
|
||||||
@@ -37,18 +65,29 @@ class GithubDetectUnusedRepos {
|
|||||||
username: this.username,
|
username: this.username,
|
||||||
};
|
};
|
||||||
|
|
||||||
const repos: ResponseWithDataArray<RepoFromGetUserRepo> =
|
const repos: ResponseWithDataArray<
|
||||||
await this.paginate(
|
RepoFromGetUserRepo
|
||||||
|
> = await this.paginate(
|
||||||
(
|
(
|
||||||
tmpFirstParam: Octokit.ReposGetForUserParams
|
tmpFirstParam: Octokit.ReposGetForUserParams
|
||||||
): Promise<ResponseFromGetUserRepo> => {
|
): Promise<ResponseFromGetUserRepo> => {
|
||||||
return (
|
return (octokit.repos.getForUser(tmpFirstParam) as any) as Promise<
|
||||||
octokit.repos.getForUser(tmpFirstParam) as any
|
ResponseFromGetUserRepo
|
||||||
) as Promise<ResponseFromGetUserRepo>;
|
>;
|
||||||
},
|
},
|
||||||
params
|
params
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Update all repo names in redux store
|
||||||
|
repos.data.forEach(repoData => {
|
||||||
|
this.reduxStore.dispatch({
|
||||||
|
type: ActionNames.InitRepo,
|
||||||
|
payload: {
|
||||||
|
repoName: repoData.name
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
const forkedRepoNames = repos.data
|
const forkedRepoNames = repos.data
|
||||||
.filter(repo => repo.fork)
|
.filter(repo => repo.fork)
|
||||||
.map(repo => repo.name);
|
.map(repo => repo.name);
|
||||||
@@ -56,6 +95,35 @@ class GithubDetectUnusedRepos {
|
|||||||
// tslint:disable-next-line:no-console
|
// tslint:disable-next-line:no-console
|
||||||
console.log(forkedRepoNames);
|
console.log(forkedRepoNames);
|
||||||
|
|
||||||
|
// Update fork filter in redux store
|
||||||
|
repos.data.forEach(repoData => {
|
||||||
|
if (forkedRepoNames.includes(repoData.name)) {
|
||||||
|
|
||||||
|
this.reduxStore.dispatch({
|
||||||
|
type: ActionNames.AddRepoFilterStatus,
|
||||||
|
payload: {
|
||||||
|
repoName: repoData.name,
|
||||||
|
filterStep: FilterSteps.forked,
|
||||||
|
filterState: {
|
||||||
|
status: FilterStatus.pass
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.reduxStore.dispatch({
|
||||||
|
type: ActionNames.AddRepoFilterStatus,
|
||||||
|
payload: {
|
||||||
|
repoName: repoData.name,
|
||||||
|
filterStep: FilterSteps.forked,
|
||||||
|
filterState: {
|
||||||
|
status: FilterStatus.fail
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const allPromiseRepoNameWithBranches = forkedRepoNames.map(repoName => {
|
const allPromiseRepoNameWithBranches = forkedRepoNames.map(repoName => {
|
||||||
return this.fetchRepoNameWithBranches(repoName);
|
return this.fetchRepoNameWithBranches(repoName);
|
||||||
});
|
});
|
||||||
@@ -134,7 +202,7 @@ class GithubDetectUnusedRepos {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const allRepoWithFlagFromCommit: RepoNameWithUnusedFlag[] = await Promise.all(
|
const allRepoWithFlagFromCommitAhead: RepoNameWithUnusedFlag[] = await Promise.all(
|
||||||
allPromiseRepoWithFlagFromCommit
|
allPromiseRepoWithFlagFromCommit
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -146,23 +214,71 @@ class GithubDetectUnusedRepos {
|
|||||||
allPromiseRepoWithFlagFromParentContrib
|
allPromiseRepoWithFlagFromParentContrib
|
||||||
);
|
);
|
||||||
|
|
||||||
|
{
|
||||||
|
// Update redux state for these 3 filters
|
||||||
|
allRepoWithFlagFromCommitAhead.forEach(tmp => {
|
||||||
|
this.reduxStore.dispatch(
|
||||||
|
{
|
||||||
|
type: ActionNames.AddRepoFilterStatus,
|
||||||
|
payload:{
|
||||||
|
repoName: tmp.repoName,
|
||||||
|
filterStep: FilterSteps.eachBranchBehindOrEven,
|
||||||
|
filterState:{
|
||||||
|
status: tmp.unused ? FilterStatus.pass : FilterStatus.fail
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
allRepoWithFlagFromForkContrib.forEach(tmp => {
|
||||||
|
this.reduxStore.dispatch(
|
||||||
|
{
|
||||||
|
type: ActionNames.AddRepoFilterStatus,
|
||||||
|
payload:{
|
||||||
|
repoName: tmp.repoName,
|
||||||
|
filterStep: FilterSteps.notForkContributor,
|
||||||
|
filterState:{
|
||||||
|
status: tmp.unused ? FilterStatus.pass : FilterStatus.fail
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
allRepoWithFlagFromParentContrib.forEach(tmp => {
|
||||||
|
this.reduxStore.dispatch(
|
||||||
|
{
|
||||||
|
type: ActionNames.AddRepoFilterStatus,
|
||||||
|
payload:{
|
||||||
|
repoName: tmp.repoName,
|
||||||
|
filterStep: FilterSteps.notParentContributor,
|
||||||
|
filterState:{
|
||||||
|
status: tmp.unused ? FilterStatus.pass : FilterStatus.fail
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
allRepoWithFlagFromCommit.length,
|
allRepoWithFlagFromCommitAhead.length,
|
||||||
allRepoWithFlagFromForkContrib.length,
|
allRepoWithFlagFromForkContrib.length,
|
||||||
'Length of `allRepoWithFlagFromCommit` and `allRepoWithFlagFromContrib` should be same'
|
'Length of `allRepoWithFlagFromCommit` and `allRepoWithFlagFromContrib` should be same'
|
||||||
);
|
);
|
||||||
|
|
||||||
const repoCount = allRepoWithFlagFromCommit.length;
|
const repoCount = allRepoWithFlagFromCommitAhead.length;
|
||||||
|
|
||||||
for (let index = 0; index < repoCount; index++) {
|
for (let index = 0; index < repoCount; index++) {
|
||||||
const tmpObjFromCommit = allRepoWithFlagFromCommit[index];
|
const tmpObjFromCommitAhead = allRepoWithFlagFromCommitAhead[index];
|
||||||
const tmpObjFromForkContrib = allRepoWithFlagFromForkContrib[index];
|
const tmpObjFromForkContrib = allRepoWithFlagFromForkContrib[index];
|
||||||
const tmpObjFromParentContrib =
|
const tmpObjFromParentContrib =
|
||||||
allRepoWithFlagFromParentContrib[index];
|
allRepoWithFlagFromParentContrib[index];
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
tmpObjFromCommit.repoName,
|
tmpObjFromCommitAhead.repoName,
|
||||||
tmpObjFromForkContrib.repoName,
|
tmpObjFromForkContrib.repoName,
|
||||||
'Reponame from same index of `allRepoWithFlagFromCommit` and `allRepoWithFlagFromContrib` should be same'
|
'Reponame from same index of `allRepoWithFlagFromCommit` and `allRepoWithFlagFromContrib` should be same'
|
||||||
);
|
);
|
||||||
@@ -173,12 +289,12 @@ class GithubDetectUnusedRepos {
|
|||||||
'Reponame from same index of `tmpObjFromForkContrib` and `tmpObjFromParentContrib` should be same'
|
'Reponame from same index of `tmpObjFromForkContrib` and `tmpObjFromParentContrib` should be same'
|
||||||
);
|
);
|
||||||
|
|
||||||
const tmpRepoName = tmpObjFromCommit.repoName;
|
const tmpRepoName = tmpObjFromCommitAhead.repoName;
|
||||||
|
|
||||||
allRepoWithFlagTillStep4.push({
|
allRepoWithFlagTillStep4.push({
|
||||||
repoName: tmpRepoName,
|
repoName: tmpRepoName,
|
||||||
unused:
|
unused:
|
||||||
tmpObjFromCommit.unused &&
|
tmpObjFromCommitAhead.unused &&
|
||||||
tmpObjFromForkContrib.unused &&
|
tmpObjFromForkContrib.unused &&
|
||||||
tmpObjFromParentContrib.unused,
|
tmpObjFromParentContrib.unused,
|
||||||
});
|
});
|
||||||
|
|||||||
+15
-6
@@ -18,8 +18,10 @@ export namespace FailReasons {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum FilterSteps {
|
export enum FilterSteps {
|
||||||
|
forked = 'forked',
|
||||||
eachBranchBehindOrEven = 'eachBranchBehindOrEven',
|
eachBranchBehindOrEven = 'eachBranchBehindOrEven',
|
||||||
notContributor = 'notContributor',
|
notForkContributor = 'notForkContributor',
|
||||||
|
notParentContributor = 'notParentContributor',
|
||||||
noCommits = 'noCommits',
|
noCommits = 'noCommits',
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,18 +32,25 @@ export enum FilterStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface RepoFilterState {
|
export interface RepoFilterState {
|
||||||
|
[FilterSteps.forked]: {
|
||||||
|
status: FilterStatus;
|
||||||
|
};
|
||||||
[FilterSteps.eachBranchBehindOrEven]: {
|
[FilterSteps.eachBranchBehindOrEven]: {
|
||||||
status: FilterStatus;
|
status: FilterStatus;
|
||||||
failReason?: FailReasons.EachBranchBehindOrEven;
|
// failReason?: FailReasons.EachBranchBehindOrEven;
|
||||||
failBranchName?: string;
|
// failBranchName?: string;
|
||||||
};
|
};
|
||||||
[FilterSteps.notContributor]: {
|
[FilterSteps.notForkContributor]: {
|
||||||
status: FilterStatus;
|
status: FilterStatus;
|
||||||
failReason?: FailReasons.NotContributor;
|
// failReason?: FailReasons.NotContributor;
|
||||||
|
};
|
||||||
|
[FilterSteps.notParentContributor]: {
|
||||||
|
status: FilterStatus;
|
||||||
|
// failReason?: FailReasons.NotContributor;
|
||||||
};
|
};
|
||||||
[FilterSteps.noCommits]: {
|
[FilterSteps.noCommits]: {
|
||||||
status: FilterStatus;
|
status: FilterStatus;
|
||||||
failReason?: FailReasons.NoCommits;
|
// failReason?: FailReasons.NoCommits;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,16 @@ export const reducer: Reducer<ApplicationState, ActionsType> = (state: Applicati
|
|||||||
const clonedAppState = new Map(state.repoStateMap);
|
const clonedAppState = new Map(state.repoStateMap);
|
||||||
clonedAppState.set(action.payload.repoName, {
|
clonedAppState.set(action.payload.repoName, {
|
||||||
filterState: {
|
filterState: {
|
||||||
|
forked: {
|
||||||
|
status: FilterStatus.waiting
|
||||||
|
},
|
||||||
eachBranchBehindOrEven: {
|
eachBranchBehindOrEven: {
|
||||||
status: FilterStatus.waiting
|
status: FilterStatus.waiting
|
||||||
},
|
},
|
||||||
notContributor: {
|
notForkContributor: {
|
||||||
|
status: FilterStatus.waiting
|
||||||
|
},
|
||||||
|
notParentContributor: {
|
||||||
status: FilterStatus.waiting
|
status: FilterStatus.waiting
|
||||||
},
|
},
|
||||||
noCommits: {
|
noCommits: {
|
||||||
|
|||||||
Reference in New Issue
Block a user