Skip to content

Commit cbc2865

Browse files
Initial commit
0 parents  commit cbc2865

File tree

11 files changed

+286
-0
lines changed

11 files changed

+286
-0
lines changed

.github/classroom/autograding.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"tests": [
3+
{
4+
"name": "Grading",
5+
"setup": "",
6+
"run": "mvn test",
7+
"input": "",
8+
"output": "",
9+
"comparison": "included",
10+
"timeout": 10,
11+
"points": 1
12+
}
13+
]
14+
}

.github/dependabot.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
groups:
9+
actions-deps:
10+
patterns:
11+
- "*"
12+
13+
# Maintain dependencies for Maven
14+
- package-ecosystem: "maven"
15+
directory: "/"
16+
schedule:
17+
interval: "weekly"
18+
groups:
19+
maven-deps:
20+
patterns:
21+
- "*"

.github/workflows/classroom.yml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: GitHub Classroom Workflow
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
checks: write
9+
actions: read
10+
contents: read
11+
pull-requests: write
12+
13+
jobs:
14+
autograding:
15+
name: Autograding
16+
runs-on: ubuntu-latest
17+
outputs:
18+
grading_status: ${{ steps.grading.outcome }}
19+
steps:
20+
- uses: actions/setup-java@v5
21+
with:
22+
distribution: 'temurin'
23+
java-version: '24'
24+
- uses: actions/checkout@v5
25+
- name: Run autograder
26+
id: grading
27+
uses: education/autograding@v1
28+
29+
ai_feedback:
30+
name: AI-Powered Feedback
31+
needs: autograding
32+
if: ${{ needs.autograding.result == 'success' }}
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v5
37+
38+
# 🧠 Read instructions
39+
- name: Read assignment instructions
40+
id: instructions
41+
run: |
42+
echo "instructions=$(cat README.md | sed 's/\"/\\\"/g' | sed 's/$/\\n/' | tr -d '\n' | sed 's/\\n/\\\\n/g')" >> $GITHUB_OUTPUT
43+
44+
# 📦 Read source code
45+
- name: Read source code
46+
id: source_code
47+
run: |
48+
{
49+
echo 'source_code<<EOF'
50+
find src/main/java -type f -name "*.java" | while read -r file; do
51+
echo "=== File: $file ==="
52+
cat "$file"
53+
echo
54+
done
55+
echo 'EOF'
56+
} >> "$GITHUB_OUTPUT"
57+
58+
# 🧪 Read test code
59+
- name: Read test code
60+
id: test_code
61+
run: |
62+
{
63+
echo 'test_code<<EOF'
64+
if [ -d "src/test/java" ]; then
65+
find src/test/java -type f -name "*.java" | while read -r file; do
66+
echo "=== File: $file ==="
67+
cat "$file"
68+
echo
69+
done
70+
else
71+
echo "No test code found."
72+
fi
73+
echo 'EOF'
74+
} >> "$GITHUB_OUTPUT"
75+
76+
# 🤖 Generate AI Feedback
77+
- name: Generate AI Feedback
78+
id: ai_feedback
79+
env:
80+
OPENROUTER_MODEL: ${{ vars.OPENROUTER_MODEL }}
81+
SYSTEM_PROMPT: ${{ vars.SYSTEM_PROMPT }}
82+
run: |
83+
INSTRUCTIONS=$(jq -Rs . <<'EOF'
84+
${{ steps.instructions.outputs.instructions }}
85+
EOF
86+
)
87+
SOURCE_CODE=$(jq -Rs . <<'EOF'
88+
${{ steps.source_code.outputs.source_code }}
89+
EOF
90+
)
91+
TEST_CODE=$(jq -Rs . <<'EOF'
92+
${{ steps.test_code.outputs.test_code }}
93+
EOF
94+
)
95+
96+
if [ -z "$INSTRUCTIONS" ] || [ -z "$SOURCE_CODE" ] || [ -z "$TEST_CODE" ]; then
97+
echo "Error: One or more required variables are not set."
98+
exit 1
99+
fi
100+
101+
PAYLOAD="Please provide feedback on the following Java assignment.\n\n--- Assignment Instructions ---\n${INSTRUCTIONS}\n\n--- Source files ---\n${SOURCE_CODE}\n\n--- Test files ---\n${TEST_CODE}"
102+
103+
JSON_CONTENT=$(jq -n \
104+
--arg model "$OPENROUTER_MODEL" \
105+
--arg system_prompt "$SYSTEM_PROMPT" \
106+
--arg payload "$PAYLOAD" \
107+
'{
108+
models: $model,
109+
messages: [
110+
{role: "system", content: $system_prompt},
111+
{role: "user", content: $payload}
112+
]
113+
}')
114+
115+
API_RESPONSE=$(echo "$JSON_CONTENT" | curl https://openrouter.ai/api/v1/chat/completions \
116+
-H "Authorization: Bearer ${{ secrets.OPENROUTER_API_KEY }}" \
117+
-H "Content-Type: application/json" \
118+
-d @-)
119+
120+
FEEDBACK_CONTENT=$(echo "$API_RESPONSE" | jq -r '.choices[0].message.content')
121+
echo "feedback<<EOF" >> $GITHUB_OUTPUT
122+
echo "$FEEDBACK_CONTENT" >> $GITHUB_OUTPUT
123+
echo "EOF" >> $GITHUB_OUTPUT
124+
125+
# 💬 Post Feedback
126+
- name: Post Feedback as PR Comment ✍️
127+
uses: actions/github-script@v7
128+
env:
129+
FEEDBACK_BODY: ${{ steps.ai_feedback.outputs.feedback }}
130+
with:
131+
github-token: ${{ secrets.GITHUB_TOKEN }}
132+
script: |
133+
const signature = "";
134+
const body = `${process.env.FEEDBACK_BODY}\n\n${signature}`;
135+
const { owner, repo } = context.repo;
136+
const issue_number = context.issue.number;
137+
138+
const { data: comments } = await github.rest.issues.listComments({
139+
owner,
140+
repo,
141+
issue_number,
142+
});
143+
144+
const previousComment = comments.find(comment => comment.body.includes(signature));
145+
146+
if (previousComment) {
147+
await github.rest.issues.updateComment({
148+
owner,
149+
repo,
150+
comment_id: previousComment.id,
151+
body,
152+
});
153+
} else {
154+
await github.rest.issues.createComment({
155+
owner,
156+
repo,
157+
issue_number,
158+
body,
159+
});
160+
}

.github/workflows/feedback.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target/
2+
/.idea/

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
![Autograding Status](https://github.com/{{REPOSITORY}}/actions/workflows/classroom.yml/badge.svg?branch=main)
2+
# 🚀 Requirements
3+
4+
Add requirements here

pom.xml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>JavaTemplate</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.release>25</maven.compiler.release>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<junit.jupiter.version>5.13.4</junit.jupiter.version>
15+
<assertj.core.version>3.27.5</assertj.core.version>
16+
<mockito.version>5.20.0</mockito.version>
17+
</properties>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.junit.jupiter</groupId>
21+
<artifactId>junit-jupiter</artifactId>
22+
<version>${junit.jupiter.version}</version>
23+
<scope>test</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.assertj</groupId>
27+
<artifactId>assertj-core</artifactId>
28+
<version>${assertj.core.version}</version>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.mockito</groupId>
33+
<artifactId>mockito-junit-jupiter</artifactId>
34+
<version>${mockito.version}</version>
35+
<scope>test</scope>
36+
</dependency>
37+
</dependencies>
38+
<build>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.jacoco</groupId>
42+
<artifactId>jacoco-maven-plugin</artifactId>
43+
<version>0.8.13</version>
44+
<configuration>
45+
<skip>true</skip>
46+
</configuration>
47+
<executions>
48+
<execution>
49+
<id>default-prepare-agent</id>
50+
<goals>
51+
<goal>prepare-agent</goal>
52+
</goals>
53+
</execution>
54+
<execution>
55+
<id>default-report</id>
56+
<phase>prepare-package</phase>
57+
<goals>
58+
<goal>report</goal>
59+
</goals>
60+
</execution>
61+
</executions>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
</project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.example;
2+
3+
public class Main {
4+
public static void main(String[] args) {
5+
6+
}
7+
}

src/main/resources/.gitkeep

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.example;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.assertj.core.api.Assertions.assertThat;
6+
7+
class MainTest {
8+
@Test
9+
void test() {
10+
assertThat(true).isTrue();
11+
}
12+
}

0 commit comments

Comments
 (0)