Giter Site home page Giter Site logo

commithelper's Issues

Custom scope question not being triggered

Hi, sorry for filing another ticket. I'd be happy to send a PR if that's okay.

Current Behavior

I've set commithelper.allowCustomScopes to true. However, this input-type question is not triggered when selecting custom as a scope:

// prompt.ts
{
	type: 'input',
	name: 'scope',
	message: 'Enter a custom scope:',
	when: answers => answers.scope === 'custom',
},
$ pnpm commit
? Select the type of change that you're committing: feat:  A new feature
? What is the scope of this change (e.g. component or file name): custom
? Write a short, imperative tense description of the change (max 87 chars):
 (0)

Expected Behavior

$ pnpm commit
? Select the type of change that you're committing: feat:  A new feature
? What is the scope of this change (e.g. component or file name): custom
? Enter a custom scope: my-custom-scope
? Write a short, imperative tense description of the change (max 78 chars):
 (0)

Steps to Reproduce

package.json

"commithelper": {
  // ...
  "allowCustomScopes": true,
  // ...
},

Possible Solutions

There are 2 questions with the name of scope and it looks like it's clashing with each other.

// prompt.ts
{
    type: 'list',
    name: 'scope',
    message: `What is the scope of this change (e.g. component or file name):`,
    choices: getChoices(config),
    when: answers => getChoices(config)(answers).length > 0,
},
{
    type: 'input',
    name: 'scope',
    message: 'Enter a custom scope:',
    when: answers => answers.scope === 'custom',
},

The second one can be changed to customScope. Afterwards, the rest of the code can be updated accordingly:

// prompt.ts
{
    type: 'input',
    name: 'customScope',
    message: 'Enter a custom scope:',
    when: answers => answers.scope === 'custom',
},
// message.ts
export interface Message {
    type: string;
    scope?: string;
    customScope?: string;
    subject: string;
    body?: string;
    breaking?: string;
    issuesClosed?: string;
}

// Update the rest of the code.

Add message to config scopes

Similar to the config's types, it would be great to have a message. Something like:

interface Scope {
  name: string;
  message: string;
}

interface Config {
  // ...
  scopes: Scope[];
  // ...
}

That way, it will be easier for new project contributors to check what each scope is for when using prompt mode.

Edit:

I'm not familiar with io-ts so I don't know if this is the correct approach on how to do this:

const ScopeNameOnly = t.string;
export type ScopeNameOnly = t.TypeOf<typeof ScopeNameOnly>;
export function isScopeNameOnly(scopes: Scope[]): boolean {
    return ScopeNameOnly.is(scopes[0]);
}

const ScopeWithMessage = t.type({
    name: t.string,
    message: t.string,
});
export type ScopeWithMessage = t.TypeOf<typeof ScopeWithMessage>;
export function isScopeWithMessage(scopes: Scope[]): boolean {
    return ScopeWithMessage.is(scopes[0]);
}

/** This way, Scope can still support the basic string[] for backwards compatibility. */
const Scope = t.union([ScopeNameOnly, ScopeWithMessage]);
export type Scope = t.TypeOf<typeof Scope>;  // Should be (string|{name:string,message:string})[].

Then getScopes(type: string, config: Config): Scope[] can transform the basic ScopeNameOnly[] to ScopeWithMessage[].

How to use as CLI?

Hi Jan Van,
I liked your project and am using it to create standardized rules for the company I work for. Being able to use the same rules on the 'prepare-commit-msg' and 'commit-msg' hooks is very good.
One question I have is:
Is it possible to use the 'prompt' part via CLI, the same as when running 'npx git-cz'?
I'm trying to use via CLI and just display the message in the terminal, I tried setting '--file' to .'git/COMMIT_EDITMSG' without success.
I would like to be able to run via CLI and continue using also on the 2 hooks I mentioned.
If you have any north I can help you in PR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.