Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .version-change-type
Original file line number Diff line number Diff line change
@@ -1 +1 @@
patch
major
1,282 changes: 673 additions & 609 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 21 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"name": "@tinystacks/ops-core-widgets",
"version": "0.0.16",
"main": "dist/index.js",
"main": "./dist/index.js",
"exports": {
"./dist/ops-types.json": "./dist/ops-types.json",
"./package.json": "./package.json",
".": {
"node": "./dist/node.js",
"browser": "./dist/browser.js",
"default": "./dist/index.js"
}
},
"type": "module",
"files": [
"dist"
Expand Down Expand Up @@ -37,13 +46,14 @@
"@jest/globals": "^29.5.0",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^14.0.0",
"@types/http-status-codes": "^1.2.0",
"@types/jest": "^29.4.0",
"@types/lodash.get": "^4.4.7",
"@types/lodash.isempty": "^4.4.7",
"@types/lodash.join": "^4.0.7",
"@types/node": "^20.2.5",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/node": "^20.3.1",
"@types/react": "^18.2.12",
"@types/react-dom": "^18.2.5",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.52.0",
"depcheck": "^1.4.3",
Expand All @@ -59,23 +69,21 @@
"react-dom": "^18.2.0",
"ts-jest": "^29.0.5",
"ts-jest-resolver": "^2.0.0",
"typescript": "^4.9.5",
"typescript": "^5.1.3",
"typescript-json-schema": "^0.57.0"
},
"dependencies": {
"@octokit/core": "^4.2.1",
"chakra-ui-markdown-renderer": "^4.1.0",
"dayjs": "^1.11.7",
"react-markdown": "^8.0.5"
},
"peerDependencies": {
"@chakra-ui/react": "2.x",
"@tinystacks/ops-core": "0.x",
"@tinystacks/ops-core": "/Users/calebcourier/Projects/ops/ops-core/tinystacks-ops-core-0.4.0.tgz",
"@tinystacks/ops-model": "0.x",
"@octokit/core": "4.x",
"chakra-ui-markdown-renderer": "4.x",
"dayjs": "1.x",
"http-status-codes": "2.x",
"lodash.get": "4.x",
"lodash.isempty": "4.x",
"lodash.isnil": "4.x",
"react": "18.x"
"react": "18.x",
"react-markdown": "8.x"
}
}
5 changes: 5 additions & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * as Models from './models/index.js';
export * as OpsTypes from './ops-types.js';
export * from './views/index.js';
export * from './utils/index.js';
export * from './core/index.js';
147 changes: 0 additions & 147 deletions src/cli.tsx

This file was deleted.

68 changes: 68 additions & 0 deletions src/controllers/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* env: node */
import { Controllers, Provider } from '@tinystacks/ops-core';
import { Cli as CliModel } from '../models/cli.js';
import { CliEnvironmentProvider } from '../core/cli-environment-provider.js';
import { Cli as CliProps } from '../ops-types.js';

import WidgetController = Controllers.Widget;

type CliOverrides = {
clear?: boolean,
run?: boolean
}

export class Cli extends CliModel implements WidgetController {

static fromJson (object: CliProps): Cli {
return new Cli(object);
}

async getData (providers?: Provider[], overrides?: CliOverrides): Promise<void> {
// This is imported like this to avoid webpack throwing up over node dependencies when this widget is used
// in the frontend next app
const depMap = {
childproc: 'child_process',
nodeutil: 'node:util'
};

const exec = (await import(depMap['childproc']))['exec'];
const promisify = (await import(depMap['nodeutil']))['promisify'];
const execPromise = promisify(exec);

const shouldRun =
// if this is the first load and runOnStart is true
(!this.hasRun && this.runOnStart === true)
// if an override told it to run
|| (overrides && overrides.run === true);

const commands: string[] = [];
let allEnvVars = {};
for (const envProvider of (providers || []) .filter(p => 'getCliEnvironment' in p)) {
const cliEnv = await (envProvider as unknown as CliEnvironmentProvider).getCliEnvironment();
allEnvVars = { ...allEnvVars, ...cliEnv };
}

allEnvVars = { ...allEnvVars, ...(this.environmentVariables || {}), PATH: process.env.PATH };

commands.push(this.command);
try {
if (shouldRun) {
const { stdout, stderr } = await execPromise(commands.join(';'), { env: allEnvVars, shell: '/bin/bash' });
this.commandResult = {
stdout: stdout.trim(),
stderr: stderr.trim()
};
this.hasRun = true;
} else if (overrides && overrides.clear === true) {
this.commandResult = {
stdout: '',
stderr: ''
};
}
} catch (e: any) {
console.error(e);
this.commandResult = { stdout: '', stderr: e.toString() };
}

}
}
86 changes: 86 additions & 0 deletions src/controllers/github.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Octokit } from '@octokit/core';
import { Controllers, Json, Provider } from '@tinystacks/ops-core';
import { GithubCredentialsProvider } from '../core/github-credentials-provider.js';
import { findProvider } from '../utils/find-provider.js';
import { Github as GithubModel } from '../models/github.js';
import { Github as GithubType } from '../ops-types.js';

import WidgetController = Controllers.Widget;

type GithubOverrides = {
host?: string;
organization?: string;
repository?: string;
};

class Github extends GithubModel implements WidgetController {
static fromJson (object: GithubType, _dependencySource?: string): Github {
return new Github(object);
}

async getData (providers?: Provider[], overrides: GithubOverrides = {}, _parameters?: Json): Promise<void> {
const {
organization = this.organization,
repository = this.repository
} = overrides;

const githubCredentialsProvider = findProvider<GithubCredentialsProvider>(providers, GithubCredentialsProvider.type);
const githubToken = githubCredentialsProvider.getCredentials().token;


const githubClient = new Octokit({ auth: githubToken, baseUrl: this.host });

const actionsResponse = await githubClient.request('GET /repos/{owner}/{repo}/actions/workflows', {
owner: organization,
repo: repository,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
});

const { workflows = [] } = actionsResponse?.data || {};

for (const workflow of workflows) {
const gqlResponse: any = await githubClient.graphql(
`query ($NODE_ID: ID!) {
node(id: $NODE_ID) {
... on Workflow {
name
url
runs (first:1) {
edges {
node {
id
createdAt
event
checkSuite {
conclusion
status
commit {
id
}
}
}
}
}
}
}
}`,
{
NODE_ID: workflow.node_id
}
);
this.actions.push({
name: gqlResponse?.node?.name,
url: gqlResponse?.node?.url,
status: gqlResponse?.node?.runs?.edges?.at(0)?.node?.checkSuite?.conclusion,
lastExecuted: gqlResponse?.node?.runs?.edges?.at(0)?.node?.createdAt,
trigger: gqlResponse?.node?.runs?.edges?.at(0)?.node?.event
});
}
}
}

export {
Github
};
7 changes: 7 additions & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './cli.js';
export * from './github.js';
export * from '../grid.js';
export * from '../json-filter.js';
export * from '../markdown.js';
export * from '../panel.js';
export * from '../tabs.js';
File renamed without changes.
Loading