Skip to content

Commit 2d05d58

Browse files
Merge pull request #2 from EficodeDemoOrg/feature/copilot-autofix
Feature/copilot autofix. Rautasta kamaa. Timanttia.
2 parents 1387b16 + 0d60bc3 commit 2d05d58

File tree

5 files changed

+110
-3
lines changed

5 files changed

+110
-3
lines changed

.github/workflows/ci-with-codeql.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This workflow uses GitHub's CodeQL to analyze your Java code for vulnerabilities and errors.
2+
3+
name: "CI with CodeQL"
4+
5+
on:
6+
push:
7+
branches: [ main ]
8+
pull_request:
9+
branches: [ main ]
10+
schedule:
11+
- cron: '0 0 * * 0'
12+
13+
jobs:
14+
analyze-and-ci:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
actions: read
18+
contents: read
19+
packages: read
20+
security-events: write
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
language: [ 'java' ]
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Initialize CodeQL
32+
uses: github/codeql-action/init@v3
33+
with:
34+
languages: ${{ matrix.language }}
35+
36+
- name: Set up JDK 11
37+
uses: actions/setup-java@v4
38+
with:
39+
distribution: 'temurin'
40+
java-version: '11'
41+
42+
- name: Build with Maven
43+
run: mvn -B clean package
44+
45+
- name: Run Checkstyle (Lint)
46+
run: mvn checkstyle:check
47+
48+
- name: Run Tests
49+
run: mvn test
50+
51+
- name: Perform CodeQL Analysis
52+
uses: github/codeql-action/analyze@v3
53+
with:
54+
category: "/language:${{matrix.language}}"

checkstyle.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
5+
6+
<module name="Checker">
7+
<module name="LineLength">
8+
<property name="max" value="120"/>
9+
</module>
10+
<module name="FileTabCharacter">
11+
<property name="eachLine" value="true"/>
12+
</module>
13+
<module name="TreeWalker">
14+
<module name="Indentation">
15+
<property name="basicOffset" value="4"/>
16+
<property name="tabWidth" value="4"/>
17+
</module>
18+
<module name="NeedBraces"/>
19+
<module name="JavadocMethod"/>
20+
<module name="JavadocType"/>
21+
<module name="LocalVariableName"/>
22+
<module name="MethodName"/>
23+
<module name="ParameterName"/>
24+
<module name="MemberName"/>
25+
<module name="ConstantName"/>
26+
<module name="PackageName"/>
27+
</module>
28+
</module>

pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,27 @@
151151
</execution>
152152
</executions>
153153
</plugin>
154+
<!-- Checkstyle plugin for code style enforcement -->
155+
<plugin>
156+
<groupId>org.apache.maven.plugins</groupId>
157+
<artifactId>maven-checkstyle-plugin</artifactId>
158+
<version>3.3.1</version>
159+
<configuration>
160+
<configLocation>checkstyle.xml</configLocation>
161+
<consoleOutput>true</consoleOutput>
162+
<failsOnError>true</failsOnError>
163+
<linkXRef>false</linkXRef>
164+
</configuration>
165+
<executions>
166+
<execution>
167+
<id>validate</id>
168+
<phase>validate</phase>
169+
<goals>
170+
<goal>check</goal>
171+
</goals>
172+
</execution>
173+
</executions>
174+
</plugin>
154175
</plugins>
155176
</build>
156177
</project>

src/main/java/com/weather/app/OpenWeatherMapClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,17 @@ public WeatherData getWeatherFromApi(String city) throws WeatherApiException {
5959
String trimmedCity = city.trim();
6060
if (!VALID_CITY_PATTERN.matcher(trimmedCity).matches()) {
6161
LOGGER.log(Level.WARNING, "Invalid city name format: {0}", trimmedCity);
62-
throw new WeatherApiException("Invalid city name format. City names should only contain letters, numbers, spaces, hyphens, and periods");
62+
throw new WeatherApiException(
63+
"Invalid city name format. City names should only contain letters, numbers, " +
64+
"spaces, hyphens, and periods");
6365
}
6466

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

6769
try {
6870
String url = buildApiUrl(trimmedCity);
69-
LOGGER.log(Level.FINE, "API request URL: {0}", url.replaceAll("appid=[^&]+", "appid=REDACTED"));
71+
LOGGER.log(Level.FINE, "API request URL: {0}",
72+
url.replaceAll("appid=[^&]+", "appid=REDACTED"));
7073
HttpRequest request = HttpRequest.newBuilder()
7174
.uri(new URI(url))
7275
.GET()

src/main/java/com/weather/app/WeatherApp.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public static void main(String[] args) {
8888

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

0 commit comments

Comments
 (0)