Skip to content
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

Add a REST endpoint to fetch the latest Git commit information #7929

Open
LazarenkoDmytro opened this issue Dec 14, 2024 · 0 comments · May be fixed by #7937
Open

Add a REST endpoint to fetch the latest Git commit information #7929

LazarenkoDmytro opened this issue Dec 14, 2024 · 0 comments · May be fixed by #7937

Comments

@LazarenkoDmytro
Copy link

LazarenkoDmytro commented Dec 14, 2024

Feature Request

Implement a REST endpoint to retrieve the latest Git commit details, including the commit hash and date, using the following specifications.

Requirements :

  • Endpoint: /commit-info
  • HTTP Method: GET
  • Response:
    • On success (200 OK):
      {
        "commitHash": "abc123456def7890ghi",
        "commitDate": "14/12/2024 16:30:00"
      }
    • On error (500 Internal Server Error):
      {
        "error": "Failed to fetch commit info: <error details>"
      }

Technical Details

  • Use the JGit library to interact with the .git repository and retrieve the latest commit information:
    • commitHash: The hash of the latest commit.
    • commitDate: The timestamp of the latest commit, formatted as dd/MM/yyyy HH:mm:ss in the Europe/Kyiv timezone.
  • Introduce a service interface (CommitInfoService) with an implementation class (CommitInfoServiceImpl) to encapsulate the logic for retrieving Git information.
  • Define a controller (CommitInfoController) to expose the endpoint and return the appropriate response.
  • Use polymorphism in the response:
    • Create an abstract DTO (CommitInfoDto) as the base class.
    • Define subclasses for:
      • Success: CommitInfoSuccessDto (fields: commitHash, commitDate).
      • Error: CommitInfoErrorDto (field: error).

Error Handling

  • Return an error response (500) if:
    • The .git directory is missing.
    • Any exception occurs while retrieving the commit information.
  • Include clear error messages for easier debugging.

Why This Feature Is Important

  • Provides visibility into the current state of the codebase at runtime.
  • Helps with debugging, auditing, and deployment validation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants