Skip to content

Commit

Permalink
Merge branch 'halo-dev:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
LIlGG authored Nov 30, 2023
2 parents 3a7e6df + 7a84f55 commit 74a28ec
Show file tree
Hide file tree
Showing 501 changed files with 23,125 additions and 1,510 deletions.
20 changes: 4 additions & 16 deletions .github/ISSUE_TEMPLATE/bug_report.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,13 @@ body:
id: environment
attributes:
value: "## Environment"
- type: input
id: version
validations:
required: true
- type: textarea
id: system-information
attributes:
label: What is version of Halo has the issue?
- type: dropdown
id: database
label: "System information"
description: "Access the actuator page of the Console, click the copy button in the upper right corner, and paste the information here."
validations:
required: true
attributes:
label: "What database are you using?"
options:
- H2
- PostgreSQL
- MySQL 5.7
- MySQL 8.x
- MariaDB
- Other
- type: dropdown
id: operation-method
validations:
Expand Down
22 changes: 5 additions & 17 deletions .github/ISSUE_TEMPLATE/bug_report.zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,13 @@ body:
id: environment
attributes:
value: "## 环境信息"
- type: input
id: version
validations:
required: true
- type: textarea
id: system-information
attributes:
label: "是什么版本出现了此问题?"
- type: dropdown
id: database
label: "系统信息"
description: "访问 Console 的概览页面,点击右上角的复制按钮,将信息粘贴到此处。"
validations:
required: true
attributes:
label: "使用的什么数据库?"
options:
- H2
- PostgreSQL
- MySQL 5.7
- MySQL 8.x
- MariaDB
- Other
- type: dropdown
id: operation-method
validations:
Expand Down Expand Up @@ -64,7 +52,7 @@ body:
id: logs
attributes:
label: "相关日志输出"
description: "请复制并粘贴任何相关的日志输出。 这将自动格式化为代码,因此无需反引号。"
description: "请复制并粘贴任何相关的日志输出。这将自动格式化为代码,因此无需反引号。"
render: shell
- type: textarea
id: additional-information
Expand Down
33 changes: 32 additions & 1 deletion .github/workflows/halo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ jobs:
distribution: 'temurin'
cache: 'gradle'
java-version: 17
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- uses: dorny/paths-filter@v2
id: changes
with:
Expand All @@ -43,6 +49,12 @@ jobs:
run: ./gradlew check
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
- name: Analyze code
if: ${{ github.event_name == 'push' }} # Due to inability to access secrets during PR, only the code pushed into the branch can be analyzed.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew sonar --info
- name: Setup console environment
if: steps.changes.outputs.console == 'true'
uses: halo-sigs/actions/admin-env-setup@main
Expand All @@ -55,10 +67,29 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: halo-sigs/actions/halo-next-docker-build@main # change the version to specific ref or release tag while the action is stable.
if: github.event_name != 'pull_request'
with:
image-name: ${{ github.event_name == 'release' && 'halo' || 'halo-dev' }}
ghcr-token: ${{ secrets.GHCR_TOKEN }}
dockerhub-user: ${{ secrets.DOCKER_USERNAME }}
dockerhub-token: ${{ secrets.DOCKER_TOKEN }}
push: ${{ github.event_name == 'pull_request' || github.event_name == 'push' || github.event_name == 'release' }}
push: ${{ github.event_name == 'push' || github.event_name == 'release' }} # we only push to GHCR if the push is to the next branch
console-ref: ${{ github.event_name == 'release' && github.ref || 'main' }}
platforms: linux/amd64,linux/arm64/v8,linux/ppc64le,linux/s390x
- uses: halo-sigs/actions/halo-next-docker-build@main
if: github.event_name == 'pull_request'
with:
image-name: halo-dev
push: false
console-ref: false
load: true
platforms: ""
- name: E2E Testing
if: github.event_name == 'pull_request'
run: |
sudo curl -L https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod u+x /usr/local/bin/docker-compose
repo=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
docker tag ghcr.io/${repo}/halo-dev:pr-${{ github.event.number }} ghcr.io/halo-dev/halo-dev:main
cd e2e && make all
8 changes: 8 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.

# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- init: ./gradlew clean build -x check && sdk install java 17.0.3-ms
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ git pull upstream master
git push
```

### E2E

Please consider adding some [e2e test cases](e2e/README.md) to make sure the APIs work as expected.

### 开发规范

请参考 [https://docs.halo.run/developer-guide/core/code-style](https://docs.halo.run/developer-guide/core/code-style),请确保所有代码格式化之后再提交。
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
FROM eclipse-temurin:17-jre as builder

WORKDIR application
ARG JAR_FILE=application/build/libs/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract

################################

FROM eclipse-temurin:17-jre
FROM ibm-semeru-runtimes:open-17-jre
MAINTAINER johnniang <[email protected]>
WORKDIR application
COPY --from=builder application/dependencies/ ./
Expand All @@ -22,4 +23,4 @@ ENV JVM_OPTS="-Xmx256m -Xms256m" \
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone

ENTRYPOINT ["sh", "-c", "java ${JVM_OPTS} org.springframework.boot.loader.JarLauncher ${0} ${@}"]
ENTRYPOINT ["sh", "-c", "java ${JVM_OPTS} org.springframework.boot.loader.launch.JarLauncher ${0} ${@}"]
16 changes: 15 additions & 1 deletion api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
plugins {
id 'java-library'
id 'halo.publish'
id "io.freefair.lombok" version "8.0.0-rc2"
id 'jacoco'
id "io.freefair.lombok" version "8.4"
}

group = 'run.halo.app'
description = 'API of halo project, connecting by other projects.'

compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
javadoc.options.encoding = "UTF-8"

repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots' }
}

dependencies {
Expand Down Expand Up @@ -75,4 +81,12 @@ java {

tasks.named('test') {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

tasks.named('jacocoTestReport') {
reports {
xml.required = true
html.required = false
}
}
4 changes: 4 additions & 0 deletions api/src/main/java/run/halo/app/core/extension/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class User extends AbstractExtension {

public static final String ROLE_NAMES_ANNO = "rbac.authorization.halo.run/role-names";

public static final String EMAIL_TO_VERIFY = "halo.run/email-to-verify";

public static final String LAST_AVATAR_ATTACHMENT_NAME_ANNO =
"halo.run/last-avatar-attachment-name";

Expand All @@ -58,6 +60,8 @@ public static class UserSpec {
@Schema(requiredMode = REQUIRED)
private String email;

private boolean emailVerified;

private String phone;

private String password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @param content is binary data of the attachment file.
* @param mediaType is media type of the attachment file.
*/
record SimpleFilePart(
public record SimpleFilePart(
String filename,
Flux<DataBuffer> content,
MediaType mediaType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public static boolean isPublished(MetadataOperator metadata) {
return labels != null && parseBoolean(labels.getOrDefault(PUBLISHED_LABEL, "false"));
}

public static boolean isPublic(PostSpec spec) {
return spec.getVisible() == null || VisibleEnum.PUBLIC.equals(spec.getVisible());
}

@Data
public static class PostSpec {
@Schema(requiredMode = RequiredMode.REQUIRED, minLength = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
import run.halo.app.extension.AbstractExtension;
import run.halo.app.extension.GVK;
Expand All @@ -27,6 +28,8 @@
public class Snapshot extends AbstractExtension {
public static final String KIND = "Snapshot";
public static final String KEEP_RAW_ANNO = "content.halo.run/keep-raw";
public static final String PATCHED_CONTENT_ANNO = "content.halo.run/patched-content";
public static final String PATCHED_RAW_ANNO = "content.halo.run/patched-raw";

@Schema(requiredMode = REQUIRED)
private SnapShotSpec spec;
Expand Down Expand Up @@ -67,4 +70,18 @@ public static void addContributor(Snapshot snapshot, String name) {
contributors.add(name);
}

/**
* Check if the given snapshot is a base snapshot.
*
* @param snapshot must not be null.
* @return true if the given snapshot is a base snapshot; false otherwise.
*/
public static boolean isBaseSnapshot(@NonNull Snapshot snapshot) {
var annotations = snapshot.getMetadata().getAnnotations();
if (annotations == null) {
return false;
}
return Boolean.parseBoolean(annotations.get(Snapshot.KEEP_RAW_ANNO));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import java.net.URI;
import java.time.Duration;
import java.util.function.Consumer;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.MediaType;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import reactor.core.publisher.Flux;
Expand All @@ -18,6 +20,25 @@
*/
public interface AttachmentService {

/**
* Uploads the given attachment to specific storage using handlers in plugins.
* <p>
* If no handler can be found to upload the given attachment, ServerError exception will be
* thrown.
*
* @param policyName is attachment policy name.
* @param groupName is group name the attachment belongs.
* @param filePart contains filename, content and media type.
* @param beforeCreating is an attachment modifier before creating.
* @return attachment.
*/
Mono<Attachment> upload(
@NonNull String username,
@NonNull String policyName,
@Nullable String groupName,
@NonNull FilePart filePart,
@Nullable Consumer<Attachment> beforeCreating);

/**
* Uploads the given attachment to specific storage using handlers in plugins. Please note
* that we will make sure the request is authenticated, or an unauthorized exception throws.
Expand Down
15 changes: 15 additions & 0 deletions api/src/main/java/run/halo/app/extension/Ref.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Objects;
import lombok.Data;
import org.springframework.lang.NonNull;

@Data
@Schema(description = "Extension reference object. The name is mandatory")
Expand Down Expand Up @@ -59,4 +60,18 @@ public static boolean groupKindEquals(Ref ref, GroupVersionKind gvk) {
return Objects.equals(ref.getGroup(), gvk.group())
&& Objects.equals(ref.getKind(), gvk.kind());
}

/**
* Check if the extension is equal to the ref.
*
* @param ref must not be null.
* @param extension must not be null.
* @return true if they are equal; false otherwise.
*/
public static boolean equals(@NonNull Ref ref, @NonNull ExtensionOperator extension) {
var gvk = extension.groupVersionKind();
var name = extension.getMetadata().getName();
return groupKindEquals(ref, gvk) && Objects.equals(ref.getName(), name);
}

}
3 changes: 3 additions & 0 deletions api/src/main/java/run/halo/app/infra/SystemSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public static class Post {
Integer tagPageSize;
Boolean review;
String slugGenerationStrategy;

String attachmentPolicyName;
String attachmentGroupName;
}

@Data
Expand Down
45 changes: 45 additions & 0 deletions api/src/main/java/run/halo/app/theme/TemplateNameResolver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package run.halo.app.theme;

import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
* <p>The {@link TemplateNameResolver} is used to resolve template name.</p>
* <code>Halo</code> has a theme mechanism, template files are provided by different themes, so
* we need a method to determine whether the template file exists in the activated theme and if
* it does not exist, provide a default template name.
*
* @author guqing
* @since 2.11.0
*/
public interface TemplateNameResolver {

/**
* Resolve template name if exists or default template name in classpath.
*
* @param exchange exchange to resolve theme to use
* @param name template
* @return template name if exists or default template name in classpath
*/
Mono<String> resolveTemplateNameOrDefault(ServerWebExchange exchange, String name);

/**
* Resolve template name if exists or default template given.
*
* @param exchange exchange to resolve theme to use
* @param name template name
* @param defaultName default template name to use if given template name not exists
* @return template name if exists or default template name given
*/
Mono<String> resolveTemplateNameOrDefault(ServerWebExchange exchange, String name,
String defaultName);

/**
* Determine whether the template file exists in the current theme.
*
* @param exchange exchange to resolve theme to use
* @param name template name
* @return <code>true</code> if the template file exists in the current theme, false otherwise
*/
Mono<Boolean> isTemplateAvailableInTheme(ServerWebExchange exchange, String name);
}
Loading

0 comments on commit 74a28ec

Please sign in to comment.