Skip to content

feat: add a new optional GITLAB_COMMENT_CUSTOM_LINKS env #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2025
Merged

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented Apr 1, 2025

PR from main branch is anti-pattern, #189 is closed accidently

Summary by CodeRabbit

  • New Features

    • Introduced an optional environment variable that allows users to customize the links displayed in GitLab merge request comments, offering greater flexibility in the feedback provided.
  • Documentation

    • Updated the documentation to detail the usage of the new configuration option for customizing comment links.

@JounQin JounQin requested a review from Copilot April 1, 2025 09:37
Copy link

changeset-bot bot commented Apr 1, 2025

🦋 Changeset detected

Latest commit: e7ea1d5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
changesets-gitlab Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

coderabbitai bot commented Apr 1, 2025

Walkthrough

The changes introduce a new optional environment variable, GITLAB_COMMENT_CUSTOM_LINKS. This variable allows users to override the default link in GitLab CLI bot comments. The update is reflected in both documentation and source code. In the code, the logic checks for this variable to determine whether to use a custom link or fall back to a default. Additionally, the relevant type definition has been updated to include this new property.

Changes

Files Change Summary
.changeset/short-queens-cover.md, README.md Documented the new optional environment variable GITLAB_COMMENT_CUSTOM_LINKS to override the default links in GitLab CLI bot comments.
src/comment.ts, src/types.ts Modified link construction in CLI bot comments to conditionally use the custom link from GITLAB_COMMENT_CUSTOM_LINKS, and updated the Env type with a new property.

Sequence Diagram(s)

sequenceDiagram
    participant CLI
    participant CommentBot
    participant Env
    participant GitLab

    CLI->>CommentBot: Request comment generation for merge request
    CommentBot->>Env: Check for GITLAB_COMMENT_CUSTOM_LINKS
    alt Custom Link Available
        Env-->>CommentBot: Return custom link
        CommentBot->>GitLab: Post comment with custom link
    else No Custom Link
        Env-->>CommentBot: Return undefined
        CommentBot->>GitLab: Post comment with default link
    end
Loading

Poem

I'm a rabbit, hopping through code with glee,
Found a new link option as spry as can be.
Custom links now in comments, oh what a sight,
Enabling users to choose what feels right.
With whiskers twitching, I celebrate this delight!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/comment.ts

Oops! Something went wrong! :(

ESLint: 9.23.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

src/types.ts

Oops! Something went wrong! :(

ESLint: 9.23.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.js
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new optional environment variable GITLAB_COMMENT_CUSTOM_LINKS that allows users to override the default links in GitLab bot comments and updates the related documentation and code to use it.

  • Added a new optional environment variable in the types definition.
  • Updated comment generation logic to conditionally use the custom link and updated the fallback URL.
  • Extended the documentation and changeset information to cover the new variable.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/types.ts Added the new optional GITLAB_COMMENT_CUSTOM_LINKS environment var.
src/comment.ts Updated comment templates to conditionally use the custom links.
README.md Documented the new GITLAB_COMMENT_CUSTOM_LINKS environment variable.
.changeset/short-queens-cover.md Created changeset file describing the feature addition.

Copy link

sonarqubecloud bot commented Apr 1, 2025

Copy link

codesandbox-ci bot commented Apr 1, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

pkg-pr-new bot commented Apr 1, 2025

Open in StackBlitz

npm i https://pkg.pr.new/changesets-gitlab@209

commit: e7ea1d5

Copy link
Contributor

github-actions bot commented Apr 1, 2025

📊 Package size report   0.3%↑

File Before After
lib/comment.js 9.0 kB 0.9%↑9.1 kB
lib/comment.js.map 7.1 kB 0.9%↑7.2 kB
lib/index.cjs 39.0 kB 0.2%↑39.1 kB
lib/types.d.ts 1.2 kB 4%↑1.2 kB
README.md 11.4 kB 1%↑11.5 kB
Total (Includes all files) 130.3 kB 0.3%↑130.7 kB
Tarball size 33.0 kB 0.3%↑33.0 kB
Unchanged files
File Size
index.d.cts 73 B
lib/api.d.ts 99 B
lib/api.js 899 B
lib/api.js.map 1.0 kB
lib/cli.d.ts 39 B
lib/cli.js 734 B
lib/cli.js.map 932 B
lib/comment.d.ts 395 B
lib/context.d.ts 74 B
lib/context.js 138 B
lib/context.js.map 228 B
lib/env.d.ts 70 B
lib/env.js 857 B
lib/env.js.map 778 B
lib/get-changed-packages.d.ts 305 B
lib/get-changed-packages.js 4.8 kB
lib/get-changed-packages.js.map 4.7 kB
lib/git-utils.d.ts 646 B
lib/git-utils.js 1.7 kB
lib/git-utils.js.map 2.2 kB
lib/index.d.ts 274 B
lib/index.js 241 B
lib/index.js.map 249 B
lib/main.d.ts 153 B
lib/main.js 3.6 kB
lib/main.js.map 3.1 kB
lib/read-changeset-state.d.ts 252 B
lib/read-changeset-state.js 650 B
lib/read-changeset-state.js.map 767 B
lib/run.d.ts 1.1 kB
lib/run.js 8.7 kB
lib/run.js.map 7.9 kB
lib/types.js 44 B
lib/types.js.map 102 B
lib/utils.d.ts 1.6 kB
lib/utils.js 4.2 kB
lib/utils.js.map 4.7 kB
LICENSE 1.1 kB
package.json 3.2 kB

🤖 This report was automatically generated by pkg-size-action

@JounQin
Copy link
Member Author

JounQin commented Apr 1, 2025

@codecov-ai-reviewer review

Copy link

codecov-ai bot commented Apr 1, 2025

On it! We are reviewing the PR and will provide feedback shortly.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/comment.ts (3)

79-84: Consider enhancing implementation to preserve the addChangesetUrl

The current implementation completely replaces the default links when GITLAB_COMMENT_CUSTOM_LINKS is defined. This means any user providing a custom value will lose the dynamic addChangesetUrl link for adding a changeset to the MR.

Consider modifying the implementation to allow users to include a placeholder for the dynamic URL:

${
  env.GITLAB_COMMENT_CUSTOM_LINKS 
-  ||
+  ? env.GITLAB_COMMENT_CUSTOM_LINKS.replace('{{addChangesetUrl}}', addChangesetUrl)
+  :
  `[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add a changeset to this MR](${addChangesetUrl})`
}

101-106: Apply the same enhancement for consistency

Similar to the previous comment, this implementation completely replaces the default links when GITLAB_COMMENT_CUSTOM_LINKS is defined, losing the dynamic addChangesetUrl.

Apply a similar enhancement for consistency:

${
  env.GITLAB_COMMENT_CUSTOM_LINKS
-  ||
+  ? env.GITLAB_COMMENT_CUSTOM_LINKS.replace('{{addChangesetUrl}}', addChangesetUrl)
+  :
  `Not sure what this means? [Click here to learn what changesets are](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this MR](${addChangesetUrl})`
}

246-384: Update the documentation to explain custom link format

If implementing the suggested placeholder approach, it would be beneficial to update the README.md documentation to explain how to use the placeholder.

Consider expanding the documentation in README.md to specify how to use the variable:

-GITLAB_COMMENT_CUSTOM_LINKS            # optional, override the links content referenced in the cli bot comment
+GITLAB_COMMENT_CUSTOM_LINKS            # optional, override the links content referenced in the cli bot comment. Use {{addChangesetUrl}} placeholder for the dynamic URL to add a changeset.

This would make it clear how users should structure their custom links to preserve the dynamic URL functionality.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7cbdff and e7ea1d5.

📒 Files selected for processing (4)
  • .changeset/short-queens-cover.md (1 hunks)
  • README.md (1 hunks)
  • src/comment.ts (2 hunks)
  • src/types.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/comment.ts (1)
src/env.ts (1)
  • env (10-33)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
.changeset/short-queens-cover.md (1)

1-5: LGTM: Well-formed changeset file

The changeset correctly indicates a minor version bump for the package "changesets-gitlab" and provides a clear description of the new feature.

README.md (1)

57-57: LGTM: Clear documentation for the new environment variable

The documentation is concise and placed appropriately in the "Environment Variables" section.

src/types.ts (1)

26-26: LGTM: Proper type definition

The new environment variable is correctly added as an optional string property to the Env type, consistent with other environment variables in this interface.

@JounQin JounQin merged commit 4ca179c into main Apr 1, 2025
19 checks passed
@JounQin JounQin deleted the custom_links branch April 1, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants