Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

misc. cleanup #30

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions .github/workflows/nlm-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: NLM Release

on:
push:
branches: [ master ]

jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npx nlm release
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
32 changes: 32 additions & 0 deletions .github/workflows/npm-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will do a clean install of node dependencies, build the source
# code and run tests across different versions of node
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: NPM Test

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
- run: npx nlm verify
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

9 changes: 0 additions & 9 deletions .yo-rc.json

This file was deleted.

2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

const fs = require('fs');
const prog = require('commander');
const git = require('simple-git/promise')().silent(true);
const git = require('simple-git').simpleGit();

const verifySetup = require('./setup');
const { UIError, log } = require('./common');
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/done.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function commitDescr({ message, hash }) {

/**
*
* @param {import('simple-git/promise').SimpleGit} git
* @param {import('simple-git').SimpleGit} git
* @param {string} feature
* @param {string} parent
*/
Expand Down
5 changes: 3 additions & 2 deletions lib/commands/merge-back.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

const { action: startAction } = require('./start');
const { UIError, cmdLine, assertNoFork } = require('../common');
const { ResetMode } = require('simple-git');

/**
* @typedef {import('../typedefs').MainBranch} MainBranch
Expand All @@ -45,7 +46,7 @@ const { UIError, cmdLine, assertNoFork } = require('../common');
* @param {MainBranch} main
*/
async function createFeatureMerge({ git, log }, from, main) {
await git.reset('hard');
await git.reset(ResetMode.HARD);
await startAction({
deps: { git, log },
args: [`merge-${from}`],
Expand All @@ -57,7 +58,7 @@ async function createFeatureMerge({ git, log }, from, main) {
}

/**
* @param {import('simple-git/promise').SimpleGit} git
* @param {import('simple-git').SimpleGit} git
* @param {string} branch
*/
async function switchAndPull(git, branch) {
Expand Down
10 changes: 5 additions & 5 deletions lib/commands/pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function findTitle(subjects) {

// extracts the organization from the "fork" remote's url
/**
* @param {import('simple-git/promise').SimpleGit} git
* @param {import('simple-git').SimpleGit} git
*/
function forkPrefix(git) {
return git.getRemotes(true).then(remotes => {
Expand All @@ -76,7 +76,7 @@ function forkPrefix(git) {
});
}

/** @param {import('simple-git/promise').SimpleGit} git */
/** @param {import('simple-git').SimpleGit} git */
async function prTemplateBodySuffix(git) {
const repoDir = await repoRootDir(git);
// See: https://docs.github.com/en/free-pro-team@latest/github/building-a-strong-community/creating-a-pull-request-template-for-your-repository
Expand All @@ -99,7 +99,7 @@ async function prAction({ deps: { git, log }, opts }) {
log('Ensuring all work is pushed to remote');
try {
await git.push();
} catch (err) {
} catch (/** @type {any} */ err) {
if (/remote contains work/.test(err.message)) {
throw new UIError(
"Your local repo is out-of-date so changes can't be pushed"
Expand All @@ -117,11 +117,11 @@ async function prAction({ deps: { git, log }, opts }) {

const gitLog = await git.log({
[`${parent}..`]: true,
splitter: Math.random(),
splitter: `${Math.random()}`,
format: { subject: '%s', body: '%b' },
});

if (gitLog.total === 0) {
if (gitLog.total === 0 || !gitLog.latest) {
log(`No commits to PR ${parent}..HEAD`);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function startAction({ deps: { git, log }, args: [branch], opts }) {
const pushSpec = `${branch}:${remoteBranch}`;
log(`Creating and pushing branch ${pushSpec}`);
await git.checkoutLocalBranch(branch);
await git.push(remote, pushSpec, { '--set-upstream': true });
await git.push(remote, pushSpec, { '--set-upstream': null });

if (opts.stash) {
log('Popping stashed changes');
Expand Down
4 changes: 2 additions & 2 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const packageJSON = require('../package.json');
const execFileAsync = promisify(execFile);

/**
* @typedef {import('simple-git/promise').SimpleGit} SimpleGit
* @typedef {import('simple-git').SimpleGit} SimpleGit
*/

class UIError extends Error {}
Expand Down Expand Up @@ -268,7 +268,7 @@ async function inferRemote(git, forceFork = false, openURLs = false) {
await git.fetch(['fork']);
log(`Added remote fork -> ${forkRemote}`);
return 'fork';
} catch (err) {
} catch (/** @type {any} */ err) {
await git.removeRemote('fork').catch(() => {});
if (!/Repository not found/.test(err.message)) throw err;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const debug = require('debug')('workflow:setup');
const { gitConfig, UIError } = require('./common');

/**
* @param {import('simple-git/promise').SimpleGit} git
* @param {import('simple-git').SimpleGit} git
*/
async function oldestSHA(git) {
const shas = (await git.raw(['rev-list', '--max-parents=0', 'HEAD']))
Expand Down Expand Up @@ -131,7 +131,7 @@ async function verifySetup(cmd, deps, doFetch = false) {
} else {
if (!doFetch) return await verifySetup(cmd, deps, true);
log(`Pushing ${name} to origin`);
await git.push('origin', `${name}:${name}`, { '--set-upstream': true });
await git.push('origin', `${name}:${name}`, { '--set-upstream': null });
}
}

Expand Down
33 changes: 32 additions & 1 deletion lib/typedefs.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
/*
* Copyright (c) 2023, Groupon, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of GROUPON nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
export type CmdDeps = {
git: import('simple-git/promise').SimpleGit;
git: import('simple-git').SimpleGit;
log(msg: string): void;
forceBool?: boolean;
};
Expand Down
Loading