Commit 0fb2d509 authored by 王雷's avatar 王雷

修改支持上传到oss并且飞书通知

parent 9096c81d
......@@ -250,7 +250,7 @@ task hot{
}
group 'com.qmai.android.plugin'
version '1.91'
version '1.92'
gradlePublish {
......
......@@ -85,16 +85,16 @@ class OssUploadTask extends DefaultTask {
.writeTimeout(60, TimeUnit.SECONDS)
.build()
Request request2 = new Request.Builder()
.url("https://oapi.dingtalk.com/robot/send?access_token=9839926e22043a7d391747e3cb14cc4e0dab7add001ce60f0d184f82e50301bc")
.url("https://open.feishu.cn/open-apis/bot/v2/hook/64bff42a-a12a-4978-8456-ccabeb25858a")
.post(requestBody)
.build()
try {
Response response2 = client.newCall(request2).execute()
String value = response2.body().string()
println("send dingding response = " + value)
println("send fs response = " + value)
} catch (Exception e) {
println("send dingding error = " + e.message)
println("send fs error = " + e.message)
}
}
......
......@@ -72,7 +72,7 @@ class PygerUploadTask extends DefaultTask {
String content = file.name + ": 下载地址: " + " https://www.pgyer.com/" +
payInfoBean.data.buildShortcutUrl + " \n二维码地址: " + payInfoBean.data.buildQRCodeURL + " \n 当前环境: " + buildType + "\n 当前分支:" + branch
println("dingding content = ${content}")
println("fs content = ${content}")
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
try {
def fsText = new FsDetailInfoModel(content)
......
package com.qmai.android.plugin
import com.google.gson.Gson
import okhttp3.*
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.json.JSONException
import org.json.JSONObject
import javax.inject.Inject
import java.util.concurrent.TimeUnit
class PygerUploadTask2 extends DefaultTask {
@OutputFile File file;
@Input String buildType;
@Input String key;
@Inject
PygerUploadTask2(File file, String buildType, String key) {
this.file = file
this.buildType = buildType
this.key = key
setGroup("pyger")
}
@TaskAction
public void upload() {
println("-------执行upload")
MultipartBody.Builder bodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM)
//add part
bodyBuilder.addFormDataPart("_api_key", key)
//add file
bodyBuilder.addFormDataPart("file", file.getName(), RequestBody
.create(MediaType.parse("*/*"), file))
//request
Request request = new Request.Builder()
.url("https://www.pgyer.com/apiv2/app/upload")
.post(bodyBuilder.build())
.build()
OkHttpClient client = new OkHttpClient.Builder()
.callTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.build()
try {
println("开始上传蒲公英")
Response response = client.newCall(request).execute()
String result = response.body().string()
Gson gson = new Gson()
PygerInfoBean payInfoBean = gson.fromJson(result, PygerInfoBean.class)
println("下载地址为: downloadUrl:" + " https://www.pgyer.com/" + payInfoBean.data.buildShortcutUrl)
println("二维码地址为:" + payInfoBean.data.buildQRCodeURL)
System.out.println("upload result: " + result)
String content = file.name + ": 下载地址: " + " https://www.pgyer.com/" + payInfoBean.data.buildShortcutUrl + " \n二维码地址: " + payInfoBean.data.buildQRCodeURL + " 当前环境: " + buildType + " 当前分支: "
//+ getBranch()
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
JSONObject json = new JSONObject()
try {
json.put("msgtype", "text:{\"content\":$content}")
json.put("text", content)
def dingDingdetail = new FsDetailInfoModel(content)
def dingdingInfo = new FsInfoModel(dingDingdetail)
RequestBody requestBody = RequestBody.create(JSON, gson.toJson(dingdingInfo))
Request request2 = new Request.Builder()
.url("https://oapi.dingtalk.com/robot/send?access_token=9839926e22043a7d391747e3cb14cc4e0dab7add001ce60f0d184f82e50301bc")
.post(requestBody)
.build()
Response response2 = client.newCall(request2).execute()
String value = response2.body().string()
println("value= " + value)
} catch (JSONException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace()
println("-----------------上传失败----------------")
println("错误原因: " + e.getMessage())
} catch (Exception e) {
println("-----------------上传失败----------------")
println("错误原因: " + e.getMessage())
}
}
@Input
boolean isInJenkins() {
Map<String, String> map = System.getenv()
if (map == null) {
return false
}
String str = map.get("Path")
if (str != null) {
//it's windows
return false
} else {
str = ""
Iterator it = map.iterator()
while (it.hasNext()) {
str += it.next()
}
return str.contains("jenkins")
}
return false;
}
//获取当前分支
@Input
String getBranch() {
return "";
if (isInJenkins()) {
return System.getenv().GIT_BRANCH
} else {
def byteOut = new ByteArrayOutputStream()
project.exec {
it.commandLine("git", "rev-parse", "--abbrev-ref", "HEAD")
it.standardOutput = byteOut
}
def response = new String(byteOut.toByteArray())
return response
}
return response
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment