Skip to content

fix: Show job external url#154

Merged
adityachoudhari26 merged 1 commit intomainfrom
job-external-url
Oct 21, 2024
Merged

fix: Show job external url#154
adityachoudhari26 merged 1 commit intomainfrom
job-external-url

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Oct 21, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new externalUrl field to the job records, enhancing job tracking with associated external URLs.
    • Updated the TargetReleaseTable component for improved styling and layout.
  • Bug Fixes

    • Enhanced logging to include the external URL for better job dispatch tracking.
  • Tests

    • Expanded test coverage for job variable determination to include scenarios for the new externalUrl property.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 21, 2024

Walkthrough

The changes in this pull request involve modifications across several files related to job dispatching and database schema updates. A new variable externalUrl is introduced in the dispatchGithubJob function to capture the GitHub workflow run URL. The database schema for the job table is updated to include an external_url column, and corresponding changes are made in the TargetReleaseTable component for UI adjustments. Additionally, test cases are enhanced to validate the new functionality, ensuring comprehensive coverage of the determineVariablesForReleaseJob function.

Changes

File Change Summary
apps/event-worker/src/job-dispatch/github.ts Added variable externalUrl to store GitHub API workflow run URL; updated return object and logging.
packages/db/drizzle/0017_huge_ultimatum.sql Added new column external_url of type text to the job table.
packages/db/drizzle/meta/_journal.json Added new entry with properties idx, version, when, and tag to the "entries" array.
packages/db/src/schema/job.ts Added new field externalUrl of type text to the job table schema.
apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/TargetReleaseTable.tsx Added className="table-fixed" to <Table>; refactored layout of TargetDropdownMenu. Removed commented-out code.
packages/job-dispatch/src/test/job-variables-deployment.test.ts Added property externalUrl to Job type; enhanced test cases for determineVariablesForReleaseJob.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GitHubAPI
    participant JobDispatcher
    participant Database

    User->>JobDispatcher: Dispatch Job
    JobDispatcher->>GitHubAPI: Call to create workflow run
    GitHubAPI-->>JobDispatcher: Return workflow run details (including URL)
    JobDispatcher->>Database: Update job record with externalUrl
    Database-->>JobDispatcher: Acknowledge update
    JobDispatcher->>User: Job dispatched successfully
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 resolve resolve all the CodeRabbit review comments.
  • @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.

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
Copy Markdown
Contributor

@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

🧹 Outside diff range and nitpick comments (5)
packages/db/drizzle/0017_huge_ultimatum.sql (1)

1-1: LGTM! Consider adding constraints for data integrity.

The SQL statement correctly adds the external_url column to the job table. This aligns with the PR objective to show job external URLs.

Consider the following enhancements for better data integrity:

  1. If the external URL will always be present for new jobs, add a NOT NULL constraint:

    ALTER TABLE "job" ADD COLUMN "external_url" text NOT NULL DEFAULT '';
  2. To optimize storage, you could use VARCHAR with a reasonable maximum length:

    ALTER TABLE "job" ADD COLUMN "external_url" VARCHAR(2048);

These suggestions are optional and depend on your specific requirements and database design principles.

packages/db/src/schema/job.ts (1)

48-48: LGTM! Consider adding a comment for clarity.

The addition of the externalUrl field is well-placed and consistent with the existing schema. It aligns with the PR objective to show the job's external URL.

Consider adding a brief comment above this field to explain its purpose, similar to other parts of the schema. For example:

// URL to the external representation of the job (e.g., GitHub workflow run URL)
externalUrl: text("external_url"),
apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/TargetReleaseTable.tsx (1)

Line range hint 93-105: External URL rendering looks good, consider truncating long URLs.

The implementation for rendering the external URL is correct and aligns with the new external_url column added to the job table. Good job on providing a fallback message when no URL is available.

Consider truncating long URLs to improve readability. You could use a utility function to shorten the displayed URL while keeping the full URL in the link. For example:

const truncateUrl = (url: string, maxLength: number = 30) => {
  return url.length > maxLength ? url.substring(0, maxLength - 3) + '...' : url;
};

Then use it in the render:

<Link
  href={job.job.externalUrl}
  rel="nofollow noreferrer"
  target="_blank"
  title={job.job.externalUrl}
>
  {truncateUrl(job.job.externalUrl)}
</Link>
packages/job-dispatch/src/__test__/job-variables-deployment.test.ts (2)

35-35: Consider adding a test case for the externalUrl property.

The externalUrl property has been added to the job object, which aligns with the database schema update. However, there are no test cases that explicitly verify the handling of this new property. To ensure comprehensive test coverage, consider adding a test case that checks if the determineVariablesForReleaseJob function correctly handles jobs with and without an externalUrl.

Would you like assistance in drafting a test case for the externalUrl property?


Line range hint 1-524: Comprehensive test coverage with room for minor improvement.

The test suite for the determineVariablesForReleaseJob function is well-structured and covers a wide range of scenarios, including direct matches, default values, and variable set overrides. The use of mocked utility functions allows for controlled testing of different scenarios, which is a good practice.

To further enhance the test suite:

  1. Consider adding a test case that explicitly checks the behavior when externalUrl is set in the job object.
  2. Add a test case for error handling, such as when required data is missing or invalid.

These additions would ensure even more comprehensive coverage of the function's behavior.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b5dfabd and e25cda4.

📒 Files selected for processing (6)
  • apps/event-worker/src/job-dispatch/github.ts (3 hunks)
  • apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/TargetReleaseTable.tsx (3 hunks)
  • packages/db/drizzle/0017_huge_ultimatum.sql (1 hunks)
  • packages/db/drizzle/meta/_journal.json (1 hunks)
  • packages/db/src/schema/job.ts (1 hunks)
  • packages/job-dispatch/src/test/job-variables-deployment.test.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (10)
packages/db/drizzle/meta/_journal.json (1)

123-129: LGTM! Verify consistency with related migration files.

The new entry in the journal is correctly formatted and consistent with the existing entries. It properly records the addition of a new migration with the tag "0017_huge_ultimatum".

To ensure full consistency, please run the following script to verify the existence of the corresponding migration file and its contents:

✅ Verification successful

Migration file verified and consistent.

The migration file 0017_huge_ultimatum.sql exists and correctly adds the external_url column to the job table.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and contents of the new migration file

# Test 1: Check if the migration file exists
fd -t f '0017_huge_ultimatum.sql' packages/db/drizzle

# Test 2: Verify the contents of the migration file
fd -t f '0017_huge_ultimatum.sql' packages/db/drizzle --exec cat {} | grep -i 'external_url'

# Expected results:
# Test 1 should return the path to the migration file
# Test 2 should show the SQL statement adding the 'external_url' column to the 'job' table

Length of output: 240

apps/event-worker/src/job-dispatch/github.ts (6)

106-106: LGTM: New variable externalUrl added correctly.

The introduction of the externalUrl variable is well-typed and appropriately initialized. Its placement is consistent with the existing code style.


109-113: LGTM: Return object from pRetry updated correctly.

The addition of url: externalUrl_ to the destructured object is consistent with the new externalUrl variable and correctly captures the workflow run URL.


130-130: LGTM: Return statement updated to include workflow run URL.

The addition of url: run.html_url in the return statement correctly captures the HTML URL of the workflow run, aligning with the earlier changes to include the external URL.


137-137: LGTM: externalUrl variable assigned correctly.

The assignment externalUrl = externalUrl_ properly stores the external URL obtained from the pRetry function, maintaining consistency with the existing code style.


147-151: LGTM: Logging and database update modified to include externalUrl.

The logging statement and database update operation have been correctly modified to include the externalUrl. This ensures that the external URL is both logged and stored in the database, improving the traceability and information available for each job.

Also applies to: 158-158


Line range hint 106-158: Overall changes look good: External URL functionality successfully implemented.

The modifications in this file effectively implement the capture, logging, and storage of the external URL for GitHub workflow runs. The changes are well-integrated, maintain consistent coding standards, and enhance the job dispatching process by providing more comprehensive information about each job. This improvement will likely aid in debugging and tracking of GitHub workflow runs.

apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/releases/[versionId]/TargetReleaseTable.tsx (3)

40-40: Verify the impact of the fixed-width table layout.

The addition of className="table-fixed" to the Table component will set a fixed-width layout for table columns. This change might affect the table's responsiveness and overall layout.

Please ensure that this change doesn't negatively impact the table's appearance or responsiveness across different screen sizes. Consider using responsive design techniques if needed.


108-119: Improved alignment of TargetDropdownMenu.

The addition of the wrapper <div className="flex justify-end"> around the TargetDropdownMenu component is a good improvement. It ensures that the dropdown menu is aligned to the right within its table cell, enhancing the overall layout and visual consistency of the table.


Line range hint 1-134: Changes align well with PR objectives.

The modifications in this file successfully implement the rendering of the job external URL, which is consistent with the PR objective "fix: Show job external url". The changes are well-integrated with the broader context of the pull request, including the addition of the external_url column in the database schema.

Key improvements:

  1. Proper rendering of the external URL with a fallback message.
  2. Improved layout for the TargetDropdownMenu.
  3. Consistent error handling and data flow.

These changes enhance the functionality and user experience of the TargetReleaseTable component.

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.

1 participant