Skip to content

Feature/copilot autofix #2

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 6 commits into from
May 19, 2025
Merged
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
54 changes: 54 additions & 0 deletions .github/workflows/ci-with-codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This workflow uses GitHub's CodeQL to analyze your Java code for vulnerabilities and errors.

name: "CI with CodeQL"

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: '0 0 * * 0'

jobs:
analyze-and-ci:
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
packages: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'java' ]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}

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

- name: Build with Maven
run: mvn -B clean package

- name: Run Checkstyle (Lint)
run: mvn checkstyle:check

- name: Run Tests
run: mvn test

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
28 changes: 28 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
<module name="LineLength">
<property name="max" value="120"/>
</module>
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="TreeWalker">
<module name="Indentation">
<property name="basicOffset" value="4"/>
<property name="tabWidth" value="4"/>
</module>
<module name="NeedBraces"/>
<module name="JavadocMethod"/>
<module name="JavadocType"/>
<module name="LocalVariableName"/>
<module name="MethodName"/>
<module name="ParameterName"/>
<module name="MemberName"/>
<module name="ConstantName"/>
<module name="PackageName"/>
</module>
</module>
21 changes: 21 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@
</execution>
</executions>
</plugin>
<!-- Checkstyle plugin for code style enforcement -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
7 changes: 5 additions & 2 deletions src/main/java/com/weather/app/OpenWeatherMapClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@ public WeatherData getWeatherFromApi(String city) throws WeatherApiException {
String trimmedCity = city.trim();
if (!VALID_CITY_PATTERN.matcher(trimmedCity).matches()) {
LOGGER.log(Level.WARNING, "Invalid city name format: {0}", trimmedCity);
throw new WeatherApiException("Invalid city name format. City names should only contain letters, numbers, spaces, hyphens, and periods");
throw new WeatherApiException(
"Invalid city name format. City names should only contain letters, numbers, " +
"spaces, hyphens, and periods");
}

LOGGER.log(Level.FINE, "Fetching weather for city: {0}", trimmedCity);

try {
String url = buildApiUrl(trimmedCity);
LOGGER.log(Level.FINE, "API request URL: {0}", url.replaceAll("appid=[^&]+", "appid=REDACTED"));
LOGGER.log(Level.FINE, "API request URL: {0}",
url.replaceAll("appid=[^&]+", "appid=REDACTED"));
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(url))
.GET()
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/weather/app/WeatherApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public static void main(String[] args) {

} catch (ConfigUtil.ConfigException e) {
LOGGER.log(Level.SEVERE, "Configuration error: " + e.getMessage(), e);
LOGGER.log(Level.SEVERE, "Please set the OPENWEATHERMAP_API_KEY environment variable or add api.key to config.properties");
LOGGER.log(Level.SEVERE,
"Please set the OPENWEATHERMAP_API_KEY environment variable or add api.key to config.properties");
exit(1);
} catch (WeatherApiException e) {
LOGGER.log(Level.SEVERE, "Error fetching weather data: " + e.getMessage(), e);
Expand Down