Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Mar 26, 2024
1 parent ef64f58 commit a214d8d
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 39 deletions.
15 changes: 13 additions & 2 deletions .github/actions/setup-supersetbot/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
name: 'Setup supersetbot'
description: 'Sets up supersetbot npm lib from the repo'
description: 'Sets up supersetbot npm lib from the repo or npm'
inputs:
from-npm:
description: 'Install from npm instead of local setup'
required: false
default: 'false' # Defaults to using the local setup
runs:
using: 'composite'
steps:
- name: Install dependencies
- name: Install supersetbot from npm
if: ${{ inputs.from-npm == 'true' }}
shell: bash
run: npm install -g supersetbot

- name: Setup supersetbot from repo
if: ${{ inputs.from-npm != 'true' }}
shell: bash
run: |
cd .github/supersetbot
Expand Down
2 changes: 1 addition & 1 deletion .github/supersetbot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supersetbot",
"version": "0.4.2",
"version": "0.4.3",
"description": "A bot for the Superset GitHub repo",
"type": "module",
"main": "src/index.js",
Expand Down
13 changes: 6 additions & 7 deletions .github/supersetbot/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export default function getCLI(context) {
func: github.syncLabels,
verbose: opts.verbose,
});
await wrapped({labels, prId, actor: opts.actor, verbose: opts.verbose, dryRun: opts.dryRun});
await wrapped({
labels, prId, actor: opts.actor, verbose: opts.verbose, dryRun: opts.dryRun,
});
});

program.command('version')
Expand Down Expand Up @@ -113,7 +115,7 @@ export default function getCLI(context) {
// eslint-disable-next-line no-await-in-loop
await github.syncLabels({
labels,
existingLabels: prIdLabelMap.get(prId).map(l => l.name),
existingLabels: prIdLabelMap.get(prId).map((l) => l.name),
prId,
...opts,
});
Expand Down Expand Up @@ -155,19 +157,16 @@ export default function getCLI(context) {
.description('Submit PR(s) to bump python dependencies')
.option('-p, --python-package <pythonPackage>', 'name of the package to bump')
.option('-u, --use-current-repo', 'Uses the current repo instead of a temporary one')
.action(async function (pythonLib) {
.action(async function () {
const opts = context.processOptions(this, ['repo']);
const github = new Github({ context });
if (!opts.pythonPackage) {
await github.createAllBumpPRs({ ...opts });
}
else {
} else {
await github.createBumpLibPullRequest({ ...opts });
}

});


program.command('docker')
.description('Generates/run docker build commands use in CI')
.option('-t, --preset <preset>', 'Build preset', /^(lean|dev|dockerize|websocket|py310|ci)$/i, 'lean')
Expand Down
2 changes: 1 addition & 1 deletion .github/supersetbot/src/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ describe('CLI Test', () => {
])('returns %s for release %s', (command, arg, contains) => {
const result = spawnSync(command, arg);
const output = result.stdout.toString();
expect(result.stdout.toString()).toContain(contains);
expect(output).toContain(contains);
});
});
2 changes: 1 addition & 1 deletion .github/supersetbot/src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class Git {

const prs = [];
const promises = [];
[...prIds].forEach(prId => {
[...prIds].forEach((prId) => {
promises.push(
this.getReleaseLabels(prId, verbose, excludeCherries)
.then((labels) => {
Expand Down
51 changes: 27 additions & 24 deletions .github/supersetbot/src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class Github {
// Extract existing labels with the given prefixes
const prefixes = ['🚢', '🍒', '🎯', '🏷️'];
const existingPrefixLabels = targetLabels
.filter((label) => prefixes.some((s) => typeof(label) === 'string' && label.startsWith(s)));
.filter((label) => prefixes.some((s) => typeof (label) === 'string' && label.startsWith(s)));

// Labels to add
const labelsToAdd = labels.filter((label) => !existingPrefixLabels.includes(label));
Expand Down Expand Up @@ -256,34 +256,40 @@ class Github {
}

async createAllBumpPRs({ verbose = false, dryRun = false, useCurrentRepo = false }) {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const tomlFilePath = path.join(__dirname, '../../..', 'pyproject.toml');
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
const tomlFilePath = path.join(dirname, '../../..', 'pyproject.toml');

try {
const data = await fs.promises.readFile(tomlFilePath, 'utf8');
// Parse the TOML data
const parsedData = toml.parse(data);

// Assuming dependencies is an array; if it's an object, you'll need to adjust this.
/* eslint-disable no-restricted-syntax, no-await-in-loop */
for (const libRange of parsedData.project.dependencies) {
const lib = libRange.match(/^[^>=<;\[\s]+/)[0];
const lib = libRange.match(/^[^>=<;[\s]+/)[0];
console.log(`Processing library: ${lib}`);
await this.createBumpLibPullRequest({lib, verbose, dryRun, useCurrentRepo});
await this.createBumpLibPullRequest({
lib, verbose, dryRun, useCurrentRepo,
});
}
} catch (err) {
console.error('Error reading or parsing the TOML file:', err);
}
}

async createBumpLibPullRequest({pythonPackage, verbose = false, dryRun = false, useCurrentRepo = false}) {

async createBumpLibPullRequest({
pythonPackage, verbose = false, dryRun = false, useCurrentRepo = false,
}) {
let cwd = './';
const shellOptions = { cwd, verbose, dryRun, raiseOnError:true, exitOnError: false };
const shellOptions = {
cwd, verbose, dryRun, raiseOnError: true, exitOnError: false,
};

if (!useCurrentRepo) {
cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'update-'));
console.log("CWD:", cwd);
console.log('CWD:', cwd);

// Clone the repo
await runShellCommand({ command: `git clone --depth 1 https://github.com/${this.context.repo} .`, ...shellOptions });
Expand All @@ -298,42 +304,39 @@ class Github {
const changed = diffResults.stdout.trim()
.split('\n')
.map((line) => line.trim())
.filter((line) => line.startsWith('+' + pythonPackage))
.filter((line) => line.startsWith(`+${pythonPackage}`))
.map((line) => line.substring(1));

if (changed.length === 0) {
console.log('No changes detected... skipping.');
} else {

console.log("LIB:", changed[0]);
console.log('LIB:', changed[0]);

// Create branch
const branchName = `supersetbot-bump-${changed[0]}`;
await runShellCommand({ command: `git checkout -b ${branchName}`, ...shellOptions });

// Commit changes
await runShellCommand({ command: `git add .`, cwd });
await runShellCommand({ command: 'git add .', cwd });
const commitMessage = `chore(🤖): bump python "${changed[0]}"`;
await runShellCommand({ command: `git commit -m "${commitMessage}"`, ...shellOptions });

if (!dryRun) {

// Push changes
await runShellCommand({ command: `git push -f origin ${branchName}`, ...shellOptions });

// Create a PR
this.octokit.pulls.create({
...this.unPackRepo(),
title: commitMessage,
head: branchName,
base: 'master',
body: `Updates the python "${pythonPackage}" library version. \n\nGenerated by @supersetbot 🤖`,
...this.unPackRepo(),
title: commitMessage,
head: branchName,
base: 'master',
body: `Updates the python "${pythonPackage}" library version. \n\nGenerated by @supersetbot 🤖`,
})
.then(({ data }) => {
.then(({ data }) => {
console.log(`Pull request created: ${data.html_url}`);
})
.catch(console.error);

})
.catch(console.error);
}
}
// Cleaning up
Expand Down
7 changes: 4 additions & 3 deletions .github/supersetbot/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { spawn} from 'child_process';
import { spawn } from 'child_process';

import { readFile } from 'fs/promises';
import { fileURLToPath } from 'url';
Expand All @@ -41,8 +41,9 @@ export async function currentPackageVersion() {
return data.version;
}


export function runShellCommand({ command, raiseOnError = true, exitOnError = true, cwd = null, verbose = false, dryRun = false }) {
export function runShellCommand({
command, raiseOnError = true, exitOnError = true, cwd = null, verbose = false, dryRun = false,
}) {
return new Promise((resolve, reject) => {
const args = command.split(/\s+/).filter((s) => !!s && s !== '\\');
const spawnOptions = {
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/bump-python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ jobs:

- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
with:
ref: master

- name: Setup supersetbot
uses: ./.github/actions/setup-supersetbot/
with:
from-npm: 'true'

- name: Install pip-compile-multi
run: pip install pip-compile-multi

- name: supersetbot bump-python -p "${{ github.event.inputs.package }}"
env:
GITHUB_TOKEN: ${{ github.token }}
Expand Down

0 comments on commit a214d8d

Please sign in to comment.