Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b60210c06 | |||
|
|
436ac6f205 | ||
| 2290ac5ecf | |||
|
|
45294b6299 | ||
| 6101e8d462 | |||
|
|
6ddd9928fc |
@@ -92,20 +92,71 @@ jobs:
|
||||
}
|
||||
EOF
|
||||
)
|
||||
response=$(curl -sS -X POST "$api_url" \
|
||||
echo "Creating release with tag: $RELEASE_TAG"
|
||||
echo "API URL: $api_url"
|
||||
echo "Target commit: $RELEASE_TARGET"
|
||||
|
||||
http_code=$(curl -sS -w "%{http_code}" -o /tmp/release_response.json -X POST "$api_url" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$payload")
|
||||
release_id=$(echo "$response" | grep -o '"id":[0-9]*' | head -n 1 | grep -o '[0-9]*')
|
||||
if [ -z "$release_id" ] || echo "$response" | grep -q '"message"'; then
|
||||
echo "Create release failed: $response"
|
||||
|
||||
response=$(cat /tmp/release_response.json)
|
||||
echo "HTTP Status: $http_code"
|
||||
echo "Response: $response"
|
||||
|
||||
if [ "$http_code" -ne 201 ]; then
|
||||
echo "Failed to create release (HTTP $http_code)"
|
||||
if echo "$response" | grep -q "already exists"; then
|
||||
echo "Release with tag $RELEASE_TAG already exists"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
release_id=$(echo "$response" | grep -oP '"id":\K[0-9]+' | head -n 1 || true)
|
||||
if [ -z "$release_id" ]; then
|
||||
echo "Failed to extract release ID from response"
|
||||
exit 1
|
||||
fi
|
||||
echo "Release created: id=$release_id"
|
||||
|
||||
echo "Listing jar files in target directory:"
|
||||
ls -lh target/*.jar || echo "No jar files found"
|
||||
|
||||
upload_count=0
|
||||
for asset_path in target/*.jar; do
|
||||
if [ ! -f "$asset_path" ]; then
|
||||
echo "Skipping non-existent file: $asset_path"
|
||||
continue
|
||||
fi
|
||||
asset_name=$(basename "$asset_path")
|
||||
curl -sS -X POST "$api_url/$release_id/assets?name=$asset_name" \
|
||||
file_size=$(stat -c%s "$asset_path" 2>/dev/null || echo "unknown")
|
||||
echo "Uploading asset: $asset_name (size: $file_size bytes)"
|
||||
|
||||
upload_url="$api_url/$release_id/assets?name=$asset_name"
|
||||
echo "Upload URL: $upload_url"
|
||||
|
||||
set +e
|
||||
http_code=$(curl -sS -w "%{http_code}" -o /tmp/asset_response.json -X POST "$upload_url" \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @"$asset_path"
|
||||
--data-binary @"$asset_path" 2>/dev/null)
|
||||
curl_exit=$?
|
||||
set -e
|
||||
|
||||
if [ $curl_exit -ne 0 ]; then
|
||||
echo "✗ Curl failed with exit code $curl_exit for $asset_name"
|
||||
cat /tmp/asset_response.json 2>/dev/null || echo "No response file"
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ "$http_code" = "201" ]; then
|
||||
echo "✓ Successfully uploaded: $asset_name"
|
||||
upload_count=$((upload_count + 1))
|
||||
else
|
||||
echo "✗ Failed to upload $asset_name (HTTP $http_code)"
|
||||
cat /tmp/asset_response.json 2>/dev/null || echo "No response body"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Upload complete: $upload_count file(s) uploaded"
|
||||
|
||||
43
pom.xml
43
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.imyeyu.network</groupId>
|
||||
<artifactId>timi-network</artifactId>
|
||||
<version>0.0.2</version>
|
||||
<version>0.0.4</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
@@ -28,10 +28,42 @@
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok-maven-plugin</artifactId>
|
||||
<version>1.18.20.0</version>
|
||||
<configuration>
|
||||
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
|
||||
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
|
||||
<addOutputDirectory>false</addOutputDirectory>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>delombok</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.36</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.11.2</version>
|
||||
<configuration>
|
||||
<sourcepath>${project.build.directory}/delombok</sourcepath>
|
||||
<encoding>UTF-8</encoding>
|
||||
<charset>UTF-8</charset>
|
||||
<docencoding>UTF-8</docencoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
@@ -65,12 +97,17 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||
<artifactId>httpclient5-fluent</artifactId>
|
||||
<version>5.2.1</version>
|
||||
<version>5.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.11.0</version>
|
||||
<version>2.13.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.40</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
||||
@@ -35,6 +35,36 @@ public class ArgMap<K, V> extends HashMap<K, V> {
|
||||
}
|
||||
|
||||
public String toURL(String url) {
|
||||
StringBuilder sb = new StringBuilder(url);
|
||||
if (url.contains("?")) {
|
||||
if (!url.endsWith("?") && !url.endsWith("&")) {
|
||||
sb.append('&');
|
||||
}
|
||||
sb.append(toURL());
|
||||
return sb.toString();
|
||||
} else {
|
||||
return url + "?" + toURL();
|
||||
}
|
||||
}
|
||||
|
||||
public static <K, V> ArgMap<K, V> of(K key, V value) {
|
||||
ArgMap<K, V> map = new ArgMap<>();
|
||||
map.put(key, value);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static <K, V> ArgMap<K, V> of(K key1, V value1, K key2, V value2) {
|
||||
ArgMap<K, V> map = new ArgMap<>();
|
||||
map.put(key1, value1);
|
||||
map.put(key2, value2);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static <K, V> ArgMap<K, V> of(K key1, V value1, K key2, V value2, K key3, V value3) {
|
||||
ArgMap<K, V> map = new ArgMap<>();
|
||||
map.put(key1, value1);
|
||||
map.put(key2, value2);
|
||||
map.put(key3, value3);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
package com.imyeyu.network;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.apache.hc.client5.http.fluent.Request;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @since 2025-07-15 14:27
|
||||
*/
|
||||
@AllArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class CommonRequest {
|
||||
|
||||
protected final Request request;
|
||||
|
||||
protected CommonRequest(Request request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public static CommonRequest wrap(Request request) {
|
||||
return new CommonRequest(request);
|
||||
}
|
||||
@@ -61,6 +61,10 @@ public class CommonRequest {
|
||||
return request.execute().returnContent().asBytes();
|
||||
}
|
||||
|
||||
public InputStream asStream() throws IOException {
|
||||
return request.execute().returnContent().asStream();
|
||||
}
|
||||
|
||||
public void execute() throws IOException {
|
||||
request.execute();
|
||||
}
|
||||
|
||||
@@ -40,16 +40,19 @@ public class FileRequest extends CommonRequest {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileRequest header(String key, String value) {
|
||||
request.addHeader(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileRequest token(String token) {
|
||||
request.addHeader("Token", token);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileRequest language(String langHeader) {
|
||||
request.addHeader("Accept-Language", langHeader);
|
||||
return this;
|
||||
|
||||
@@ -52,16 +52,19 @@ public class GsonRequest extends CommonRequest {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GsonRequest header(String key, String value) {
|
||||
request.addHeader(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GsonRequest token(String token) {
|
||||
request.addHeader("Token", token);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GsonRequest language(String langHeader) {
|
||||
request.addHeader("Accept-Language", langHeader);
|
||||
return this;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Network {
|
||||
dp.browse(URI.create(Encoder.url(url)));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,16 +48,19 @@ public class ProgressiveRequest extends FileRequest {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressiveRequest header(String key, String value) {
|
||||
request.addHeader(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressiveRequest token(String token) {
|
||||
request.addHeader("Token", token);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProgressiveRequest language(String langHeader) {
|
||||
request.addHeader("Accept-Language", langHeader);
|
||||
return this;
|
||||
|
||||
@@ -34,16 +34,19 @@ public class TimiRequest extends GsonRequest {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimiRequest header(String key, String value) {
|
||||
request.addHeader(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimiRequest token(String token) {
|
||||
request.addHeader("Token", token);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimiRequest language(String langHeader) {
|
||||
request.addHeader("Accept-Language", langHeader);
|
||||
return this;
|
||||
|
||||
27
src/test/java/com/imyeyu/network/test/ArgMapTest.java
Normal file
27
src/test/java/com/imyeyu/network/test/ArgMapTest.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.imyeyu.network.test;
|
||||
|
||||
import com.imyeyu.network.ArgMap;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2026-02-10 12:45
|
||||
*/
|
||||
public class ArgMapTest {
|
||||
|
||||
@Test
|
||||
public void toURLTest() {
|
||||
assert ArgMap.of("key", "value").toURL("/detail").equals("/detail?key=value");
|
||||
assert ArgMap.of("key", "value").toURL("/detail?").equals("/detail?key=value");
|
||||
assert ArgMap.of("key", "value").toURL("/detail?id=123").equals("/detail?id=123&key=value");
|
||||
assert ArgMap.of("key", "value").toURL("/detail?id=123&").equals("/detail?id=123&key=value");
|
||||
assert ArgMap.of("key", "value").toURL("http://localhost/detail").equals("http://localhost/detail?key=value");
|
||||
assert ArgMap.of("key", "value").toURL("http://localhost/detail?").equals("http://localhost/detail?key=value");
|
||||
|
||||
String uri = ArgMap.of("key", "value").toURL("/detail?id=123");
|
||||
String url = ArgMap.of("newKey", "newValue").toURL("http://localhost/test" + uri);
|
||||
assert url.equals("http://localhost/test/detail?id=123&key=value&newKey=newValue");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user