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

spotless pre-commit 설정 #5

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
**/.DS_Store
**/.classpath
**/.dockerignore
**/.env
#**/.env
**/.factorypath
**/.git
**/.gitignore
Expand All @@ -23,8 +23,8 @@
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose.y*ml
#**/docker-compose*
#**/compose.y*ml
**/Dockerfile*
**/secrets.dev.yaml
**/values.dev.yaml
Expand Down
22 changes: 16 additions & 6 deletions .github/workflows/random_reviewer/reviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ function selectRandomReviewer() {
]
}

async function sendDiscordMsg(reviewer) {
async function sendDiscordMsg(reviewer, title) {
const webhook = process.env.DISCORD_WEBHOOK;

const msg = {
content: createMsg(reviewer)
content: createMsg(reviewer, title)
}

await fetch(webhook, {
Expand All @@ -31,15 +31,25 @@ async function sendDiscordMsg(reviewer) {
})
}

function createMsg(reviewer) {
return "리뷰해주세요\n" + "* PR: " + `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/pulls/${github.context.payload.pull_request.number}`
+ "\n* 담당자: @" + "<@&" + member[reviewer] + ">"
function createMsg(reviewer, title) {
return title + "\n" + "* PR: " + `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/pulls/${github.context.payload.pull_request.number}`
+ "\n* 담당자: " + "<@!" + member[reviewer] + ">"
}

async function main() {
const githubClient = github.getOctokit(process.env.REVIEW_TOKEN);
const reviewer = selectRandomReviewer();

const { owner, repo } = github.context.repo;

const pr = await githubClient.rest.pulls.get(
{
owner: owner,
repo: repo,
pull_number: github.context.payload.pull_request.number
}
)

githubClient.rest.pulls.requestReviewers(
{
owner: github.context.repo.owner,
Expand All @@ -51,7 +61,7 @@ async function main() {
.then((res) => console.log("reviewer assign success: ", res))
.catch((err) => console.log("reviewer assign failed:", err));

sendDiscordMsg(reviewer)
sendDiscordMsg(reviewer, pr.data.title)
.then(() => console.log("message send success"))
.catch(() => console.log("message send failed"));
}
Expand Down
20 changes: 19 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id 'com.diffplug.spotless' version '6.25.0'
}

group = 'com.example'
group = 'com.gdgoc'
version = '0.0.1-SNAPSHOT'

java {
Expand All @@ -27,6 +27,8 @@ repositories {

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.postgresql:postgresql'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand Down Expand Up @@ -56,3 +58,19 @@ spotless {
endWithNewline()
}
}

tasks.register("updateGitHooks", Copy) {
from "./scripts/pre-commit"
into ".git/hooks"
onlyIf {
System.getenv("NO_GIT_HOOKS") == "true"
}
}
tasks.register("executableGitHooks", Exec) {
commandLine "chmod", "ug+x", ".git/hooks/pre-commit"
dependsOn(updateGitHooks)
onlyIf {
System.getenv("NO_GIT_HOOKS") == "true"
}
}
compileJava.dependsOn(executableGitHooks)
33 changes: 32 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
services:
server:
env_file:
- ./env/server.env
- ./env/db.env
environment:
- NO_GIT_HOOKS="true"
platform: linux/arm64
build:
context: .
ports:
- 8080:8080
- "8080:8080"
depends_on:
- db

db:
env_file:
- ./env/db.env
image: postgres
restart: always
ports:
- "5432:5432"
volumes:
- data:/data/db

pgadmin:
container_name: pgadmin
image: dpage/pgadmin4
ports:
- "8088:80"
environment:
- [email protected]
- PGADMIN_DEFAULT_PASSWORD=0000
depends_on:
- db

volumes:
data:
16 changes: 16 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

# 변경된 파일들 이름만 추출하여 저장
stagedFiles=$(git diff --staged --name-only)

# SpotlessApply 실행
echo "Running spotlessApply. Formatting code..."

./gradlew spotlessApply

# 변경사항이 발생한 파일들 다시 git add
for file in $stagedFiles; do
if test -f "$file"; then
git add "$file"
fi
done
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.example.study_group;
package com.gdgoc.study_group;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class StudyGroupApplication {

public static void main(String[] args) {
SpringApplication.run(StudyGroupApplication.class, args);
}

public static void main(String[] args) {
SpringApplication.run(StudyGroupApplication.class, args);
}
}
17 changes: 10 additions & 7 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
server:
port: 8080
address:
port: ${SERVER_PORT}
address: ${SERVER_ADDRESS}

spring:
application:
name: study-group
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://${POSTGRES_URL}:${POSTGRES_PORT}/${POSTGRES_DB}
username: ${POSTGRES_USER}
password: ${POSTGRES_PASSWORD}

jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
format_sql: true
create_empty_composites:
enabled: true
show-sql: true
dialect: org.hibernate.dialect.PostgreSQLDialect
show-sql: true

This file was deleted.

Loading