Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions .github/workflows/build-test-lint-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# - name: Cache Maven dependencies
# uses: actions/cache@v3
# with:
# path: ~/.m2/repository
# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
# restore-keys: |
# ${{ runner.os }}-maven-
cache: 'maven'

- name: Install dependencies
run: mvn clean install -DskipTests
run: chmod +x mvnw && ./mvnw clean install -DskipTests

- name: Run Tests
run: mvn test
run: ./mvnw test
env:
ENV: production
DATABASE_URL: ${{ secrets.DATABASE_URL }}
Expand All @@ -49,27 +42,36 @@ jobs:
MAIL_SERVICE_STARTTLS: ${{ secrets.MAIL_SERVICE_STARTTLS }}
MAIL_SERVICE_DOMAIN_NAME: ${{ secrets.MAIL_SERVICE_DOMAIN_NAME }}

- name: Upload test reports
if: always()
uses: actions/upload-artifact@v4
with:
name: test-reports
path: |
target/surefire-reports/
target/site/jacoco/

# lint-and-format:
# runs-on: ubuntu-latest
# needs: build-and-test
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
# uses: actions/checkout@v4
#
# - name: Set up JDK 17
# uses: actions/setup-java@v3
# uses: actions/setup-java@v4
# with:
# java-version: '17'
# distribution: 'temurin'
#
# - name: Run Checkstyle
# run: mvn checkstyle:check
# run: ./mvnw checkstyle:check
#
# - name: Run PMD
# run: mvn pmd:check
# run: ./mvnw pmd:check
#
# - name: Run SpotBugs
# run: mvn spotbugs:check
# run: ./mvnw spotbugs:check

# - name: Verify code formatting with Spotless (excluding Javadocs)
# run: mvn spotless:check -Dspotless.apply.skip
# run: ./mvnw spotless:check -Dspotless.apply.skip
46 changes: 46 additions & 0 deletions .github/workloads/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: LibraryMan-API CI Pipeline

# 1. Automated Triggers: Triggers on every push or PR to key branches
on:
push:
branches: [ "main", "Build", "Test", "Deploy", "CI" ]
pull_request:
branches: [ "main" ]

jobs:
pipeline:
runs-on: ubuntu-latest

steps:
# 2. Setup Phase
- name: Checkout Repository Code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven

# 3. Automation Phase
- name: Make Maven Wrapper Executable
run: chmod +x mvnw

- name: Build and Execute 111 Unit Tests
# This automates the build and test process within the pipeline
run: ./mvnw clean test

- name: Generate JaCoCo Coverage Report
# This generates the report for the "Accessible Reports" requirement
run: ./mvnw jacoco:report

# 4. Reporting Phase (Deliverables)
- name: Archive Test & Coverage Reports
if: always() # Ensures reports are uploaded even if tests fail
uses: actions/upload-artifact@v4
with:
name: assignment-reports
path: |
target/surefire-reports/
target/site/jacoco/
Comment on lines +1 to +46
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify workflow file locations. Expected: runnable workflows are under .github/workflows/.
find .github -maxdepth 3 -type f \( -name '*.yml' -o -name '*.yaml' \) -print | sort

Repository: ajaynegi45/LibraryMan-API

Length of output: 286


Move this workflow to .github/workflows/.

The file is currently at .github/workloads/main.yml, but GitHub Actions only discovers workflows in the .github/workflows/ directory. This workflow will not run in its current location.

Proposed fix
-.github/workloads/main.yml
+.github/workflows/main.yml
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workloads/main.yml around lines 1 - 46, The workflow file titled
"LibraryMan-API CI Pipeline" (contains job id "pipeline" and steps like
"Checkout Repository Code", "Set up JDK 17", "Build and Execute 111 Unit Tests")
is in the wrong location; move that YAML to the repository's GitHub Actions
workflows directory so GitHub can discover and run it, keeping the same contents
and filenames, and verify the job key "pipeline" and artifact upload step remain
intact after relocation.

50 changes: 42 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand All @@ -68,7 +74,7 @@
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.12.0</version>
<version>0.11.5</version>
<scope>runtime</scope>
</dependency>

Expand Down Expand Up @@ -124,12 +130,40 @@
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<plugins>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>


<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.11</version>
<executions>

<!-- Attach JaCoCo agent -->
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>

<!-- Generate report -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>

</executions>
</plugin>

</plugins>
</build>

</project>
14 changes: 14 additions & 0 deletions pulls/2/description
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Fixes #1

Modernize the CI pipeline to produce accessible test and coverage reports as downloadable artifacts.

### Workflow (`build-test-lint-format.yml`)
- Upgrade `actions/checkout`, `actions/setup-java`, to **v4**
- Replace commented-out `actions/cache@v3` with `setup-java`'s built-in `cache: 'maven'`
- Switch from `mvn` to `./mvnw` for reproducible builds via the Maven wrapper
- Add `actions/upload-artifact@v4` (`if: always()`) to archive Surefire + JaCoCo reports

### Build (`pom.xml`)
- Add `jacoco-maven-plugin` 0.8.12 with `prepare-agent` and `report` goals bound to the `test` phase

After this, every push/PR run will produce a downloadable `test-reports` artifact containing `target/surefire-reports/` and `target/site/jacoco/.
Comment on lines +11 to +14
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Keep the PR description aligned with the actual build config.

The description says JaCoCo 0.8.12, but pom.xml configures 0.8.11; line 14 also leaves the artifact path code span unclosed.

Proposed wording fix
- Add `jacoco-maven-plugin` 0.8.12 with `prepare-agent` and `report` goals bound to the `test` phase
+ Add `jacoco-maven-plugin` 0.8.11 with `prepare-agent` and `report` goals bound to the `test` phase

-After this, every push/PR run will produce a downloadable `test-reports` artifact containing `target/surefire-reports/` and `target/site/jacoco/.
+After this, every push/PR run will produce a downloadable `test-reports` artifact containing `target/surefire-reports/` and `target/site/jacoco/`.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pulls/2/description` around lines 11 - 14, Update the PR description to match
the actual pom.xml JaCoCo version and fix the unclosed code span: change the
described JaCoCo version string "0.8.12" to "0.8.11" to match the pom.xml
configuration, and close the artifact path code span so "target/site/jacoco/" is
properly fenced; ensure the description text and the pom.xml version string
remain consistent going forward.

10 changes: 7 additions & 3 deletions src/main/java/com/libraryman_api/book/BookController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
* This controller provides endpoints for performing CRUD operations on books,
* including retrieving all books, getting a book by its ID, adding a new book,
* updating an existing book, and deleting a book.
* * Version: 1.1
*/
@RestController
@RequestMapping("/api")
@RequestMapping("/api/v1/books") //Versioning API path -> provide more context
Comment on lines 22 to +23
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify controller mappings and whether tests cover BookController URLs.
# Expected: either tests/docs updated for /api/v1/books, or compatibility for old book routes.
rg -n -C 3 '@RequestMapping|@GetMapping|@PostMapping|@PutMapping|@DeleteMapping' src/main src/test
rg -n -C 3 '/api/v1/books|/api/.*/book|BookController|MockMvc|WebTestClient' src/test README.md

Repository: ajaynegi45/LibraryMan-API

Length of output: 26317


Address API versioning inconsistency and add test coverage for BookController endpoints.

The /api/v1/books base path introduces explicit versioning that is inconsistent with other resource controllers (MemberController and BorrowingController use /api, while NewsletterController and AnalyticsController use feature-specific paths without versioning). This breaks the existing API contract for all book endpoints if they previously used /api/books/.... No test coverage found for the BookController routes. Either standardize the versioning approach across all controllers, add a compatibility route for existing clients, or document this as an intentional breaking change with corresponding test coverage.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/libraryman_api/book/BookController.java` around lines 22 -
23, The BookController currently uses `@RequestMapping`("/api/v1/books") which
introduces an inconsistent versioned base path; change it to match the project's
existing convention (use "/api/books") or add a compatibility mapping that
preserves "/api/books" while keeping "/api/v1/books" (e.g., add a second
`@RequestMapping` or alias) and then add unit/integration tests covering all
BookController endpoints (tests should target the controller class
BookController and validate paths, status codes, and payloads for
create/get/update/delete routes) to ensure no regression for existing clients.

public class BookController {

@Autowired
Expand Down Expand Up @@ -80,7 +81,8 @@ public BookDto addBook(@Valid @RequestBody BookDto bookDto) {

/**
* Updates an existing book in the library.
*
* This operation is restricted to LIBRARIAN and ADMIN roles.
*
* @param id the ID of the book to update.
* @param bookDtoDetails the {@link Book} object containing the updated book details.
* @return the updated {@link Book} object.
Expand All @@ -93,13 +95,15 @@ public BookDto updateBook(@PathVariable int id, @Valid @RequestBody BookDto book

/**
* Deletes a book from the library by its ID.
* Provides confirmation message upon successful deletion.
*
* @param id the ID of the book to delete.
*/
@DeleteMapping("delete-book/{id}")
@PreAuthorize("hasRole('LIBRARIAN') or hasRole('ADMIN')")
public void deleteBook(@PathVariable int id) {
public ResponseEntity<String> deleteBook(@PathVariable int id) {
bookService.deleteBook(id);
return ResponseEntity.ok("Book with ID " + id + " has been successfully deleted from the system.");
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=

spring.jpa.hibernate.ddl-auto=create-drop