mirror of
https://github.com/bendtherules/github-delete-unused-repos.git
synced 2026-08-18 13:52:59 +00:00
Add redux store and package
This commit is contained in:
+2
-1
@@ -35,7 +35,8 @@
|
|||||||
"@octokit/rest": "^15.6.2",
|
"@octokit/rest": "^15.6.2",
|
||||||
"babel-polyfill": "^6.26.0",
|
"babel-polyfill": "^6.26.0",
|
||||||
"bottleneck": "^2.3.1",
|
"bottleneck": "^2.3.1",
|
||||||
"octonode": "^0.9.2"
|
"octonode": "^0.9.2",
|
||||||
|
"redux": "^4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^22.0.1",
|
"@types/jest": "^22.0.1",
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { Action } from 'redux';
|
||||||
|
import { FilterSteps, RepoFilterState } from './model';
|
||||||
|
|
||||||
|
export enum ActionNames {
|
||||||
|
InitUserName = 'InitUserName',
|
||||||
|
InitRepo = 'InitRepo',
|
||||||
|
AddRepoFilterStatus = 'AddRepoFilterStatus',
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InitUserNameArgs extends Action<ActionNames.InitUserName> {
|
||||||
|
payload: {
|
||||||
|
userName: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InitRepoArgs extends Action<ActionNames.InitRepo> {
|
||||||
|
payload: {
|
||||||
|
repoName: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AddRepoFilterStatusArgs
|
||||||
|
extends Action<ActionNames.AddRepoFilterStatus> {
|
||||||
|
payload: {
|
||||||
|
repoName: string;
|
||||||
|
filterStep: FilterSteps;
|
||||||
|
filterState: RepoFilterState[FilterSteps];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ActionsType =
|
||||||
|
InitUserNameArgs
|
||||||
|
| InitRepoArgs
|
||||||
|
| AddRepoFilterStatusArgs;
|
||||||
+3
-44
@@ -1,44 +1,3 @@
|
|||||||
import { Store, createStore, applyMiddleware } from 'redux';
|
export * from './model';
|
||||||
|
export * from './actions';
|
||||||
export namespace FailReasons {
|
export * from './reducers';
|
||||||
export enum EachBranchBehindOrEven {
|
|
||||||
'remote branch doesn\'t exist',
|
|
||||||
'forked branch ahead'
|
|
||||||
};
|
|
||||||
|
|
||||||
export enum NotContributor {
|
|
||||||
'contributor in self repo',
|
|
||||||
'contributor in parent repo'
|
|
||||||
};
|
|
||||||
|
|
||||||
export enum NoCommits {
|
|
||||||
'commit in self repo',
|
|
||||||
'commit in parent repo'
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GithubRepoFilterState {
|
|
||||||
eachBranchBehindOrEven: {
|
|
||||||
fail: boolean,
|
|
||||||
failReason: FailReasons.EachBranchBehindOrEven
|
|
||||||
failBranchName: string
|
|
||||||
},
|
|
||||||
notContributor: {
|
|
||||||
fail: boolean,
|
|
||||||
failReason: FailReasons.NotContributor
|
|
||||||
},
|
|
||||||
noCommits: {
|
|
||||||
fail: boolean,
|
|
||||||
failReason: FailReasons.NoCommits
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type GithubRepoFilterStates = Map<string, {
|
|
||||||
filterState: GithubRepoFilterState
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export interface ApplicationState {
|
|
||||||
username: string;
|
|
||||||
repoStates: GithubRepoFilterStates;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import { Store, createStore, applyMiddleware } from 'redux';
|
||||||
|
|
||||||
|
export namespace FailReasons {
|
||||||
|
export enum EachBranchBehindOrEven {
|
||||||
|
"remote branch doesn't exist",
|
||||||
|
'forked branch ahead',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum NotContributor {
|
||||||
|
'contributor in self repo',
|
||||||
|
'contributor in parent repo',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum NoCommits {
|
||||||
|
'commit in self repo',
|
||||||
|
'commit in parent repo',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum FilterSteps {
|
||||||
|
eachBranchBehindOrEven = 'eachBranchBehindOrEven',
|
||||||
|
notContributor = 'notContributor',
|
||||||
|
noCommits = 'noCommits',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum FilterStatus {
|
||||||
|
'pass',
|
||||||
|
'fail',
|
||||||
|
'waiting',
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RepoFilterState {
|
||||||
|
[FilterSteps.eachBranchBehindOrEven]: {
|
||||||
|
status: FilterStatus;
|
||||||
|
failReason?: FailReasons.EachBranchBehindOrEven;
|
||||||
|
failBranchName?: string;
|
||||||
|
};
|
||||||
|
[FilterSteps.notContributor]: {
|
||||||
|
status: FilterStatus;
|
||||||
|
failReason?: FailReasons.NotContributor;
|
||||||
|
};
|
||||||
|
[FilterSteps.noCommits]: {
|
||||||
|
status: FilterStatus;
|
||||||
|
failReason?: FailReasons.NoCommits;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RepoFilterStateMap = Map<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
filterState: RepoFilterState;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
|
||||||
|
export interface ApplicationState {
|
||||||
|
username: string;
|
||||||
|
repoStateMap: RepoFilterStateMap;
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import { Reducer, createStore, Store } from 'redux';
|
||||||
|
import { ApplicationState, FilterStatus, RepoFilterState } from './model';
|
||||||
|
import { ActionNames, InitUserNameArgs, InitRepoArgs, AddRepoFilterStatusArgs, ActionsType } from './actions';
|
||||||
|
|
||||||
|
export const initialState: ApplicationState = {
|
||||||
|
username: '',
|
||||||
|
repoStateMap: new Map()
|
||||||
|
};
|
||||||
|
|
||||||
|
export const reducer: Reducer<ApplicationState, ActionsType> = (state: ApplicationState = initialState, action) => {
|
||||||
|
// We'll augment the action type on the switch case to make sure we have
|
||||||
|
// all the cases handled.
|
||||||
|
switch (action.type) {
|
||||||
|
case ActionNames.InitUserName:
|
||||||
|
return { ...state, username: action.payload.userName };
|
||||||
|
|
||||||
|
case ActionNames.InitRepo:
|
||||||
|
{
|
||||||
|
const clonedAppState = new Map(state.repoStateMap);
|
||||||
|
clonedAppState.set(action.payload.repoName, {
|
||||||
|
filterState: {
|
||||||
|
eachBranchBehindOrEven: {
|
||||||
|
status: FilterStatus.waiting
|
||||||
|
},
|
||||||
|
notContributor: {
|
||||||
|
status: FilterStatus.waiting
|
||||||
|
},
|
||||||
|
noCommits: {
|
||||||
|
status: FilterStatus.waiting
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return { ...state, repoStateMap: clonedAppState };
|
||||||
|
}
|
||||||
|
case ActionNames.AddRepoFilterStatus:
|
||||||
|
{
|
||||||
|
const clonedAppState = new Map(state.repoStateMap);
|
||||||
|
let clonedRepoState = JSON.parse(JSON.stringify(clonedAppState.get(action.payload.repoName))) as (
|
||||||
|
{
|
||||||
|
filterState: RepoFilterState;
|
||||||
|
} | undefined
|
||||||
|
);
|
||||||
|
|
||||||
|
if (clonedRepoState !== undefined) {
|
||||||
|
clonedRepoState.filterState[action.payload.filterStep] = action.payload.filterState;
|
||||||
|
|
||||||
|
clonedAppState.set(action.payload.repoName, clonedRepoState);
|
||||||
|
return { ...state, repoStateMap: clonedAppState };
|
||||||
|
} else {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export function createAppStore(): Store<ApplicationState, ActionsType> {
|
||||||
|
return createStore<
|
||||||
|
ApplicationState, ActionsType, {}, {}
|
||||||
|
>(
|
||||||
|
reducer,
|
||||||
|
initialState
|
||||||
|
) as any as Store<ApplicationState, ActionsType>;
|
||||||
|
};
|
||||||
+80
-69
@@ -2,140 +2,151 @@ import * as Octokit from '@octokit/rest';
|
|||||||
|
|
||||||
// +++ All typescript definitions +++
|
// +++ All typescript definitions +++
|
||||||
interface RequestOptions {
|
interface RequestOptions {
|
||||||
method: string;
|
method: string;
|
||||||
url: string;
|
url: string;
|
||||||
headers: any;
|
headers: any;
|
||||||
query?: string;
|
query?: string;
|
||||||
variables?: Variables;
|
variables?: Variables;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Result {
|
interface Result {
|
||||||
headers: {
|
headers: {
|
||||||
status: string;
|
status: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OctokitError {
|
interface OctokitError {
|
||||||
code: number;
|
code: number;
|
||||||
status: string;
|
status: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OctokitMod extends Octokit {
|
export interface OctokitMod extends Octokit {
|
||||||
// The following are added because Octokit does not expose the hook.error, hook.before, and hook.after methods
|
// The following are added because Octokit does not expose the hook.error, hook.before, and hook.after methods
|
||||||
hook: {
|
hook: {
|
||||||
error: (when: 'request', callback: (error: OctokitError, options: RequestOptions) => void) => void;
|
error: (
|
||||||
before: (when: 'request', callback: (result: Result, options: RequestOptions) => void) => void;
|
when: 'request',
|
||||||
after: (when: 'request', callback: (result: Result, options: RequestOptions) => void) => void;
|
callback: (error: OctokitError, options: RequestOptions) => void
|
||||||
};
|
) => void;
|
||||||
|
before: (
|
||||||
|
when: 'request',
|
||||||
|
callback: (result: Result, options: RequestOptions) => void
|
||||||
|
) => void;
|
||||||
|
after: (
|
||||||
|
when: 'request',
|
||||||
|
callback: (result: Result, options: RequestOptions) => void
|
||||||
|
) => void;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Variables {
|
interface Variables {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResponseWithDataArray<T> {
|
export interface ResponseWithDataArray<T> {
|
||||||
data: T[];
|
data: T[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ResponseWithMetaLink {
|
interface ResponseWithMetaLink {
|
||||||
meta: {
|
meta: {
|
||||||
link: string;
|
link: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResponseWithDataArrayAndMeta<T> extends ResponseWithDataArray<T>, ResponseWithMetaLink {
|
export interface ResponseWithDataArrayAndMeta<T>
|
||||||
}
|
extends ResponseWithDataArray<T>,
|
||||||
|
ResponseWithMetaLink {}
|
||||||
|
|
||||||
export interface ResponseFromGetUserRepo extends ResponseWithMetaLink {
|
export interface ResponseFromGetUserRepo extends ResponseWithMetaLink {
|
||||||
data: RepoFromGetUserRepo[];
|
data: RepoFromGetUserRepo[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResponseFromGetBranches extends ResponseWithMetaLink {
|
export interface ResponseFromGetBranches extends ResponseWithMetaLink {
|
||||||
data: BranchFromGetBranches[];
|
data: BranchFromGetBranches[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResponseFromGetRepo {
|
export interface ResponseFromGetRepo {
|
||||||
data: RepoFromGetRepo;
|
data: RepoFromGetRepo;
|
||||||
meta: {};
|
meta: {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResponseFromCompareCommits {
|
export interface ResponseFromCompareCommits {
|
||||||
data: {
|
data: {
|
||||||
status: string;
|
status: string;
|
||||||
ahead_by: number;
|
ahead_by: number;
|
||||||
behind_by: number;
|
behind_by: number;
|
||||||
total_commits: number;
|
total_commits: number;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResponseFromGetContributors extends ResponseWithMetaLink {
|
export interface ResponseFromGetContributors extends ResponseWithMetaLink {
|
||||||
data: OwnerFromGetContributors[] | undefined;
|
data: OwnerFromGetContributors[] | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RepoFromGetUserRepo {
|
export interface RepoFromGetUserRepo {
|
||||||
default_branch: string;
|
default_branch: string;
|
||||||
description: string;
|
description: string;
|
||||||
fork: boolean;
|
fork: boolean;
|
||||||
full_name: string;
|
full_name: string;
|
||||||
homepage: string;
|
homepage: string;
|
||||||
id: number;
|
id: number;
|
||||||
language: string;
|
language: string;
|
||||||
name: string;
|
name: string;
|
||||||
owner: OwnerFromGetUserRepo;
|
owner: OwnerFromGetUserRepo;
|
||||||
private: boolean;
|
private: boolean;
|
||||||
pushed_at: string;
|
pushed_at: string;
|
||||||
url: string;
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OwnerFromGetUserRepo {
|
interface OwnerFromGetUserRepo {
|
||||||
avatar_url: string;
|
avatar_url: string;
|
||||||
gravatar_id: string;
|
gravatar_id: string;
|
||||||
html_url: string;
|
html_url: string;
|
||||||
id: number;
|
id: number;
|
||||||
login: string;
|
login: string;
|
||||||
repos_url: string;
|
repos_url: string;
|
||||||
type: UserType;
|
type: UserType;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type OwnerFromGetContributors = OwnerFromGetUserRepo;
|
export type OwnerFromGetContributors = OwnerFromGetUserRepo;
|
||||||
|
|
||||||
enum UserType {
|
enum UserType {
|
||||||
User = 'User'
|
User = 'User',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BranchFromGetBranches {
|
export interface BranchFromGetBranches {
|
||||||
name: string;
|
name: string;
|
||||||
commit: CommitFromGetBranches;
|
commit: CommitFromGetBranches;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CommitFromGetBranches {
|
interface CommitFromGetBranches {
|
||||||
sha: string;
|
sha: string;
|
||||||
url: string;
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RepoFromGetRepo {
|
interface RepoFromGetRepo {
|
||||||
parent: RepoFromGetUserRepo;
|
parent: RepoFromGetUserRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RepoNameWithUnusedFlag {
|
export interface RepoNameWithUnusedFlag {
|
||||||
repoName: string;
|
repoName: string;
|
||||||
unused: boolean;
|
unused: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RepoNameWithBranches {
|
export interface RepoNameWithBranches {
|
||||||
repoName: string;
|
repoName: string;
|
||||||
branches: BranchFromGetBranches[];
|
branches: BranchFromGetBranches[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RepoNameWithParentRepo {
|
export interface RepoNameWithParentRepo {
|
||||||
repoName: string;
|
repoName: string;
|
||||||
parentRepo: RepoFromGetUserRepo;
|
parentRepo: RepoFromGetUserRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RepoNameWithBranchesAndParent extends RepoNameWithBranches, RepoNameWithParentRepo {
|
export interface RepoNameWithBranchesAndParent
|
||||||
}
|
extends RepoNameWithBranches,
|
||||||
|
RepoNameWithParentRepo {}
|
||||||
|
|
||||||
export interface ObjectWithPerPage {
|
export interface ObjectWithPerPage {
|
||||||
per_page?: number;
|
per_page?: number;
|
||||||
}
|
}
|
||||||
// --- End all typescript definitions ---
|
// --- End all typescript definitions ---
|
||||||
|
|||||||
@@ -3450,6 +3450,10 @@ js-tokens@^3.0.0, js-tokens@^3.0.2:
|
|||||||
version "3.0.2"
|
version "3.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
|
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
|
||||||
|
|
||||||
|
"js-tokens@^3.0.0 || ^4.0.0":
|
||||||
|
version "4.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
|
||||||
|
|
||||||
js-yaml@3.6.1:
|
js-yaml@3.6.1:
|
||||||
version "3.6.1"
|
version "3.6.1"
|
||||||
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.6.1.tgz#6e5fe67d8b205ce4d22fad05b7781e8dadcc4b30"
|
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.6.1.tgz#6e5fe67d8b205ce4d22fad05b7781e8dadcc4b30"
|
||||||
@@ -3677,6 +3681,12 @@ loose-envify@^1.0.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
js-tokens "^3.0.0"
|
js-tokens "^3.0.0"
|
||||||
|
|
||||||
|
loose-envify@^1.1.0:
|
||||||
|
version "1.4.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
|
||||||
|
dependencies:
|
||||||
|
js-tokens "^3.0.0 || ^4.0.0"
|
||||||
|
|
||||||
loud-rejection@^1.0.0:
|
loud-rejection@^1.0.0:
|
||||||
version "1.6.0"
|
version "1.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/loud-rejection/-/loud-rejection-1.6.0.tgz#5b46f80147edee578870f086d04821cf998e551f"
|
resolved "https://registry.yarnpkg.com/loud-rejection/-/loud-rejection-1.6.0.tgz#5b46f80147edee578870f086d04821cf998e551f"
|
||||||
@@ -4664,6 +4674,13 @@ redent@^1.0.0:
|
|||||||
indent-string "^2.1.0"
|
indent-string "^2.1.0"
|
||||||
strip-indent "^1.0.1"
|
strip-indent "^1.0.1"
|
||||||
|
|
||||||
|
redux@^4.0.0:
|
||||||
|
version "4.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.0.tgz#aa698a92b729315d22b34a0553d7e6533555cc03"
|
||||||
|
dependencies:
|
||||||
|
loose-envify "^1.1.0"
|
||||||
|
symbol-observable "^1.2.0"
|
||||||
|
|
||||||
regenerate@^1.2.1:
|
regenerate@^1.2.1:
|
||||||
version "1.4.0"
|
version "1.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"
|
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"
|
||||||
@@ -5354,6 +5371,10 @@ supports-color@^5.1.0, supports-color@^5.3.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
has-flag "^3.0.0"
|
has-flag "^3.0.0"
|
||||||
|
|
||||||
|
symbol-observable@^1.2.0:
|
||||||
|
version "1.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
|
||||||
|
|
||||||
symbol-tree@^3.2.2:
|
symbol-tree@^3.2.2:
|
||||||
version "3.2.2"
|
version "3.2.2"
|
||||||
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"
|
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"
|
||||||
|
|||||||
Reference in New Issue
Block a user