Skip to content

feat: add optional GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE env #196

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 4 commits into from
Apr 1, 2025

Conversation

crysadrak
Copy link
Contributor

@crysadrak crysadrak commented Dec 3, 2024

This PR adds a new optional GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE environment variable to automatically resolve added discussion when changeset is present, if you want always resolve the discussion, you should actually use GITLAB_COMMENT_TYPE=note instead, default true.

This feature should help in projects where ability to merge depends on all resolved discussions. After little internal research all developers appreciate the notification about missing changeset but also this unresolved discussion comment might by useless when changeset check is ok.

close #190
close #191

Summary by CodeRabbit

  • New Features

    • Introduced an optional configuration setting that automatically resolves discussions when changes are detected, offering greater workflow flexibility.
  • Documentation

    • Updated integration instructions to clearly outline new and existing configuration options, ensuring consistency and clarity.
  • Refactor

    • Streamlined management of configuration settings, including the removal of an obsolete debug credential option to enhance security.

Copy link

changeset-bot bot commented Dec 3, 2024

🦋 Changeset detected

Latest commit: e5b8119

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

codesandbox-ci bot commented Dec 3, 2024

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.

@JounQin JounQin changed the title Add GITLAB_COMMENT_DISCUSSION_AUTORESOLVE optional environment feat: add optional GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE env Apr 1, 2025
@JounQin JounQin force-pushed the add-discussion-resolve branch from e57dece to f8630a7 Compare April 1, 2025 06:56
Copy link

coderabbitai bot commented Apr 1, 2025

Walkthrough

The pull request introduces a new environment variable, GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE, which controls whether discussions are automatically resolved when a changeset exists (defaulting to true). Documentation in both the changeset file and README has been updated to describe this and other GitLab-related variables, with formatting and naming adjustments for clarity. In the source code, variable names are refactored (e.g., renaming GITLAB_COMMENT_TYPE to commentType), environment variable usage is streamlined, a new truthy value helper (TRUTHY_VALUES) is added, and the DEBUG_GITLAB_CREDENTIAL property is removed or made optional.

Changes

Files Change Summary
.changeset/..., README.md Added documentation for the new env variable GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE and updated formatting and descriptions for existing GitLab-related variables.
src/comment.ts, src/main.ts, src/env.ts Refactored environment variable handling – renamed variables (e.g., GITLAB_COMMENT_TYPEcommentType), updated conditional logic for auto-resolving discussions, and removed DEBUG_GITLAB_CREDENTIAL.
src/types.ts, src/utils.ts Updated type definitions by adding an optional GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE and making DEBUG_GITLAB_CREDENTIAL optional; introduced the TRUTHY_VALUES constant for checks.

Sequence Diagram(s)

sequenceDiagram
    participant CI as CI/CD Pipeline
    participant CH as Comment Handler
    participant Env as Environment Config
    participant API as GitLab API

    CI->>CH: Process changeset for merge request
    CH->>Env: Retrieve env variables (incl. GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE)
    alt Changeset detected
        CH->>Env: Evaluate auto-resolve flag via TRUTHY_VALUES
        alt Flag is truthy
            CH->>API: Trigger discussion resolution
        else Flag is false
            CH->>API: Post note comment
        end
    else No changeset
        CH->>API: Create discussion comment for missing changeset
    end
Loading

Assessment against linked issues

Objective (Issues) Addressed Explanation
Support different comment behavior based on changeset presence [#190, #191] The PR does not implement the proposed GITLAB_COMMENT_TYPE_IF_MISSING parameter; it only adds auto-resolve logic.

Poem

I'm a clever little rabbit with a hop and a cheer,
Adding flags and tweaking code to make things clear.
Auto-resolving discussions when a changeset's in sight,
My burrow of code is now extra light!
Hop along, dear devs, in GitLab's moonlit night!
🐰🌙

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/utils.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/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/main.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)

  • 1 others
✨ 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

pkg-pr-new bot commented Apr 1, 2025

Open in StackBlitz

npm i https://pkg.pr.new/un-ts/changesets-gitlab@196

commit: e5b8119

@JounQin
Copy link
Member

JounQin commented Apr 1, 2025

Thanks @crysadrak for your contribution! I changed the env name to GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE, and only 1/true options available, and also default true.

If you want to always resolve the discussion, you should actually use GITLAB_COMMENT_TYPE=note instead.

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: 2

🔭 Outside diff range comments (1)
src/main.ts (1)

24-68: 💡 Verification agent

🧩 Analysis chain

Missing implementation for GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE

The PR introduces the type definition for GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE, but its actual implementation seems to be missing from the files under review. Based on the AI summary, this might be implemented in src/comment.ts, which is not included in this review.


🌐 Web query:

Can you verify if src/comment.ts in the changesets-gitlab repository contains the implementation for GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE?

💡 Result:

The src/comment.ts implementation in changesets-gitlab does not include GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE based on available documentation[3][7]. The closest related feature is the GITLAB_COMMENT_TYPE environment variable introduced in v0.9.0, which lets users choose between GitLab's discussion threads (discussion) or individual notes (note) for comments[7].

Key points from the search results:

  1. Input variables include INPUT_COMMENT for commit messages and GITLAB_COMMENT_TYPE for comment format selection[3]
  2. The changelog[7] shows no implementation of auto-resolve functionality for discussions
  3. Issue tracking[6] mentions basic commenting capabilities but no resolution automation

For comment management, the tool focuses on MR interaction rather than discussion thread resolution workflows[1][3][7]. Developers would need to handle discussion resolution through GitLab's native mechanisms or custom scripting.

Citations:


Review Notice: Missing Implementation for Auto-Resolve Feature

The PR introduces the type definition for GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE, but verification confirms that there is no corresponding implementation in src/comment.ts. Instead, the current functionality only supports comment type selection through the GITLAB_COMMENT_TYPE environment variable. Please clarify whether the auto-resolve feature should be implemented or if the type definition is no longer needed, and adjust accordingly.

  • Action Required:
    • Implement the auto-resolve functionality in src/comment.ts if intended, or remove the unused type definition to prevent confusion.
🧹 Nitpick comments (2)
.changeset/swift-berries-exist.md (1)

5-5: Improve changeset description readability

The description is informative but could benefit from improved formatting with proper punctuation to enhance readability.

-feat: add a new optional `GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE` environment variable to automatically resolve added discussion when changeset is present, if you want always resolve the discussion, you should actually use `GITLAB_COMMENT_TYPE=note` instead, default `true`
+feat: add a new optional `GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE` environment variable to automatically resolve added discussion when changeset is present. If you want to always resolve the discussion, you should use `GITLAB_COMMENT_TYPE=note` instead. Default value is `true`.
src/comment.ts (1)

312-323: New feature: Auto-resolving discussions when changeset exists.

This implementation checks if a changeset exists and if auto-resolving is enabled (defaulting to true with '1'). The conditional can be simplified since TRUTHY_VALUES already contains '1', making the default truthy.

  if (
    hasChangeset &&
-   TRUTHY_VALUES.has(env.GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE || '1')
+   TRUTHY_VALUES.has(env.GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE ?? '1')
  ) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cac8607 and f8630a7.

📒 Files selected for processing (7)
  • .changeset/swift-berries-exist.md (1 hunks)
  • README.md (1 hunks)
  • src/comment.ts (6 hunks)
  • src/env.ts (0 hunks)
  • src/main.ts (3 hunks)
  • src/types.ts (1 hunks)
  • src/utils.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • src/env.ts
🧰 Additional context used
🧬 Code Definitions (2)
src/main.ts (4)
src/types.ts (1)
  • MainCommandOptions (1-4)
src/env.ts (1)
  • env (10-33)
src/git-utils.ts (1)
  • setupUser (6-13)
src/utils.ts (1)
  • TRUTHY_VALUES (175-175)
src/comment.ts (2)
src/env.ts (1)
  • env (10-33)
src/utils.ts (1)
  • TRUTHY_VALUES (175-175)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (14)
src/utils.ts (1)

175-175: Clean addition of TRUTHY_VALUES utility

The new constant TRUTHY_VALUES is a sensible addition that will provide a consistent way to check truthy string values across the codebase. Using a Set is an efficient choice for frequent lookups.

.changeset/swift-berries-exist.md (1)

1-5: LGTM - Minor version bump is appropriate

This changeset correctly identifies the change as a minor version bump, which is appropriate for adding a new feature without breaking existing functionality.

src/types.ts (1)

25-25: Making DEBUG_GITLAB_CREDENTIAL optional is a good improvement

Changing DEBUG_GITLAB_CREDENTIAL to be optional aligns with its usage pattern in the codebase and provides better type safety.

src/main.ts (3)

13-18: Import of new TRUTHY_VALUES utility

The addition of the TRUTHY_VALUES import improves code organization by centralizing the definition of what constitutes a truthy value in environment variables.


24-24: Simplified environment variable destructuring

Reducing the number of destructured variables improves maintainability by making it clearer when environment variables are being accessed.


29-29: Direct access to environment variables

Consistently accessing properties through the env object makes the code more predictable and easier to trace.

Also applies to: 33-33, 48-48, 68-68

src/comment.ts (5)

23-23: Added import for the new auto-resolve feature.

The TRUTHY_VALUES import is used to determine whether discussions should be automatically resolved based on the new environment variable setting.


249-251: Good variable renaming for clarity.

Renaming from environment variable names to more concise variable names improves readability and follows better variable naming conventions.


261-261: Direct reference to environment variable instead of destructured variable.

Using the environment variable directly is consistent with the approach taken for other references in this code segment.


289-301: Improved consistency in environment variable access.

Direct references to env properties instead of using destructured variables improves consistency throughout the codebase and ensures the most up-to-date values are used.


355-355: Consistent variable name in error message.

The error message correctly references the renamed commentType variable.

README.md (3)

51-55: Documentation formatting improvements.

Consistent spacing and improved documentation formatting make the README more readable and professional.


56-56: Documentation for the new auto-resolve feature.

The documentation clearly explains the purpose of the new GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE environment variable and its default behavior. It also points out that using GITLAB_COMMENT_TYPE=note is an alternative approach if users want to always resolve discussions.


57-58: Consistent formatting for remaining environment variables.

Continuing the formatting improvements for the remaining environment variables enhances the overall documentation quality.

@JounQin
Copy link
Member

JounQin commented Apr 1, 2025

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.

@coderabbitai Please run yarn build first before lint and test.

@JounQin JounQin force-pushed the add-discussion-resolve branch from f8630a7 to e5b8119 Compare April 1, 2025 07:10
Copy link

sonarqubecloud bot commented Apr 1, 2025

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 (1)
.changeset/swift-berries-exist.md (1)

1-5: Changeset accurately documents the new feature.

The changeset correctly describes the new environment variable GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE and its purpose. It provides clear information about the default value and alternative options.

Consider using more formal language in the documentation.

For better readability and professionalism, consider rephrasing "if you want to" to something like "if you prefer to" or "to always resolve discussions".

-feat: add a new optional `GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE` environment variable to automatically resolve added discussion when changeset is present, if you want to always resolve the discussion, you should actually use `GITLAB_COMMENT_TYPE=note` instead, default `true`
+feat: add a new optional `GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE` environment variable to automatically resolve added discussion when changeset is present. To always resolve discussions, use `GITLAB_COMMENT_TYPE=note` instead. Default value is `true`
🧰 Tools
🪛 LanguageTool

[style] ~5-~5: Consider using a more polite wording.
Context: ...ssion when changeset is present, if you want to always resolve the discussion, you s...

(IF_YOU_WANT)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f8630a7 and e5b8119.

📒 Files selected for processing (7)
  • .changeset/swift-berries-exist.md (1 hunks)
  • README.md (1 hunks)
  • src/comment.ts (6 hunks)
  • src/env.ts (0 hunks)
  • src/main.ts (3 hunks)
  • src/types.ts (1 hunks)
  • src/utils.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • src/env.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/utils.ts
  • README.md
  • src/main.ts
  • src/types.ts
🧰 Additional context used
🧬 Code Definitions (1)
src/comment.ts (2)
src/env.ts (1)
  • env (10-33)
src/utils.ts (1)
  • TRUTHY_VALUES (175-175)
🪛 LanguageTool
.changeset/swift-berries-exist.md

[style] ~5-~5: Consider using a more polite wording.
Context: ...ssion when changeset is present, if you want to always resolve the discussion, you s...

(IF_YOU_WANT)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (6)
src/comment.ts (6)

23-23: Appropriate import of TRUTHY_VALUES utility.

The import adds the necessary utility to check for truthy values in the environment variable.


247-251: Variable renaming improves code clarity.

Renaming environment variables to more concise local variables (GITLAB_COMMENT_TYPEcommentType and GITLAB_ADD_CHANGESET_MESSAGEcommitMessage) enhances readability. The removal of other destructured variables in favor of direct access via env object later in the code is also a good practice as it centralizes environment variable access.


261-261: Direct access to environment variable is consistent with the refactoring.

This change aligns with the earlier refactoring that removed destructured variables in favor of direct access through the env object.


289-301: Consistent use of env object for environment variables.

The changes in this string construction are aligned with the earlier refactoring, using direct access to the env object properties instead of destructured variables. The conditional for commitMessage is also appropriately updated.


355-355: Error message updated to match variable name.

The error message has been correctly updated to use commentType instead of the previous environment variable name.


309-324:

✅ Verification successful

Well-implemented auto-resolve feature for discussions.

The new feature to automatically resolve discussions when a changeset is present has been properly implemented. The code appropriately checks:

  1. If a changeset exists
  2. If auto-resolve is enabled (defaulting to true)

This addresses the PR objectives of helping projects where merge capability depends on resolved discussions.

Verify default value behavior.

The implementation uses env.GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE || '1' which means it will default to '1' (truthy) if the environment variable is not set. This aligns with the stated default in the changeset.


🏁 Script executed:

#!/bin/bash
# Search for any tests or documentation that verify the default behavior
rg -A 5 "GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE" --type ts --type md

Length of output: 1253


Auto-resolve feature and default behavior verified

The auto-resolve implementation in src/comment.ts (lines 309-324) correctly checks for a changeset and uses the environment variable GITLAB_COMMENT_DISCUSSION_AUTO_RESOLVE || '1', ensuring that discussions default to auto-resolve when the variable is unset. The repository’s README and type definitions in src/types.ts confirm that this behavior is intentional and aligns with the design objectives.

@JounQin JounQin merged commit b681513 into un-ts:main Apr 1, 2025
15 checks passed
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.

I would like to start a discussion if no changeset is found, and a note if changeset is present
2 participants