Skip to content

Conversation

@jamietanna
Copy link
Contributor

Changes

As a way to make it more predictable what the possible states the
result in a given Repository finished log message can be, we can
wrap these into a type.

This requires a slight refactor where these are used to make sure that
Typescript is happy with the value being returned.

Context

Please select one of the below:

  • This closes an existing Issue: #
  • This doesn't close an Issue, but I accept the risk that this PR may be closed if maintainers disagree with its opening or implementation

AI assistance disclosure

Did you use AI tools to create any part of this pull request?

Please select one option and, if yes, briefly describe how AI was used (e.g., code, tests, docs) and which tool(s) you used.

  • No — I did not use AI for this contribution.
  • Yes — minimal assistance (e.g., IDE autocomplete, small code completions, grammar fixes).
  • Yes — substantive assistance (AI generated non‑trivial portions of code, tests, or documentation).
  • Yes — other (please describe):

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

The public repository:

@jamietanna jamietanna added the mend:customer-request Issues requested on behalf of a Mend customer label Dec 4, 2025
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some small suggestions

REPOSITORY_DISABLED,
REPOSITORY_DISABLED_BY_CONFIG,
REPOSITORY_NO_CONFIG,
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use as const here to make typescript happy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do i.e.

  const disabledMessages = [
    REPOSITORY_CLOSED_ONBOARDING,
    REPOSITORY_DISABLED,
    REPOSITORY_DISABLED_BY_CONFIG,
    REPOSITORY_NO_CONFIG,
  ] as const;
  if (disabledMessages.some((m) => err.message === m)) {
    logger.info('Repository is disabled - skipping');
    return err.message;
  }

But I see:

lib/workers/repository/error.ts:67:5 - error TS2322: Type 'string' is not assignable to type 'RepositoryResult'.

67     return err.message;
       ~~~~~~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's unfortunate 🫣

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. use includes instead of some

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. use includes instead of some

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using includes:

  const disabledMessages = [
    REPOSITORY_CLOSED_ONBOARDING,
    REPOSITORY_DISABLED,
    REPOSITORY_DISABLED_BY_CONFIG,
    REPOSITORY_NO_CONFIG,
  ] as const;
  if (disabledMessages.includes(err.message)) {
    logger.info('Repository is disabled - skipping');
    return err.message;
  }

results in:

lib/workers/repository/error.ts:65:33 - error TS2345: Argument of type 'string' is not assignable to parameter of type '"disabled" | "disabled-closed-onboarding" | "disabled-by-config" | "disabled-no-config"'.

65   if (disabledMessages.includes(err.message)) {
                                   ~~~~~~~~~~~

lib/workers/repository/error.ts:67:5 - error TS2322: Type 'string' is not assignable to type 'RepositoryResult'.

67     return err.message;
       ~~~~~~

@jamietanna jamietanna requested a review from viceice December 5, 2025 14:21
Copy link
Member

@viceice viceice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

As a way to make it more predictable what the possible states the
`result` in a given `Repository finished` log message can be, we can
wrap these into a type.

This requires a slight refactor where these are used to make sure that
Typescript is happy with the value being returned.

We can capture the common groups of errors (which are then present as a
`RepositoryResult`) and expose that to be used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mend:customer-request Issues requested on behalf of a Mend customer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants