Skip to content

Commit

Permalink
feat(mp-sheet): add update mp sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
novlan1 committed Apr 19, 2024
1 parent 14659c8 commit 67ecdd7
Show file tree
Hide file tree
Showing 26 changed files with 641 additions and 80 deletions.
47 changes: 47 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
# 更新日志

### [1.3.80](https://github.com/novlan1/t-comm/compare/v1.3.79...v1.3.80) (2024-04-16)


### Features 🎉

* **mp-ci:** add update mp-sheet v0 ([04481f2](https://github.com/novlan1/t-comm/commit/04481f2e6d378642f1c21208bc0de8f4a6e82341))

### [1.3.79](https://github.com/novlan1/t-comm/compare/v1.3.78...v1.3.79) (2024-04-16)


### Features 🎉

* **mp-ci:** add qq-mp result update sheet ([f908f2f](https://github.com/novlan1/t-comm/commit/f908f2ffb884805e5867afd926aef4924da89aa2))


### Chore 🚀

* update test script ([6988ce7](https://github.com/novlan1/t-comm/commit/6988ce79cacef2654395dc095d679ade8d637055))

### [1.3.78](https://github.com/novlan1/t-comm/compare/v1.3.77...v1.3.78) (2024-04-16)


### Features 🎉

* **report-rd-platform:** 支持多个腾讯云项目 ([182293b](https://github.com/novlan1/t-comm/commit/182293b83ceff8fd9a49e3dbf825afde8f9c21d4))
* **tam:** canvas报错后依然返回数据 ([2533704](https://github.com/novlan1/t-comm/commit/25337044cfdc7cbc9a9934327fac7056aebea921))

### [1.3.77](https://github.com/novlan1/t-comm/compare/v1.3.76...v1.3.77) (2024-04-15)


### Features 🎉

* **open-location:** add get open locaiton href ([1c3f9ea](https://github.com/novlan1/t-comm/commit/1c3f9ea276d455dee34fe9bdf8e96dcb0f00c4a5))
* **pipeline:** 支持传入overTimeConfigList ([f59c271](https://github.com/novlan1/t-comm/commit/f59c27196de8f7b3620fa1013b418faaf1a7f948))

### [1.3.76](https://github.com/novlan1/t-comm/compare/v1.3.75...v1.3.76) (2024-04-10)


### Documentation 📖

* update comment ([9a26b8e](https://github.com/novlan1/t-comm/commit/9a26b8e8947d76d1848e68ee747ef4d4759f460e))


### Features 🎉

* **mp:** add saveMpImage ([be2841b](https://github.com/novlan1/t-comm/commit/be2841b82d9e27b6f4bfc356089ca3a0a080144d))

### [1.3.75](https://github.com/novlan1/t-comm/compare/v1.3.74...v1.3.75) (2024-04-03)


Expand Down
4 changes: 2 additions & 2 deletions docs/zh/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
**示例**

```typescript
getBranch()
getGitCurBranch()

// => master
```
Expand All @@ -66,7 +66,7 @@ getBranch()
**示例**

```ts
getGitCommitInfo()
getGitCommitMessage()
// '优化一部分文档'
```
<a name="getGitCommitInfo"></a>
Expand Down
33 changes: 33 additions & 0 deletions docs/zh/mp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[[toc]]

## 引入

```ts
import { saveMpImage } from 't-comm';

// or

import { saveMpImage} from 't-comm/lib/mp/index';
```


## `saveMpImage(url, options)`


**描述**:<p>小程序下保存图片</p>

**参数**


| 参数名 | 类型 | 描述 |
| --- | --- | --- |
| url | <code>string</code> | <p>图片地址</p> |
| options | <code>object</code> | <p>提示选项</p> |



**示例**

```ts
saveMpImage('https://xxx.png');
```
1 change: 1 addition & 0 deletions docs/zh/open-location.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ openLocationInMp({
name,
address,
});
```
<a name="openLocationInH5"></a>

## `openLocationInH5(param)`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "t-comm",
"version": "1.3.75",
"version": "1.3.80",
"description": "丰富易用的工具库",
"main": "lib/index.js",
"module": "lib/index.esm.js",
Expand Down
4 changes: 2 additions & 2 deletions script/trial/tencent-doc/convert-file-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const {
OPEN_ID,
} = require('./config');

const FILE_ID = '300000000$HNFkydcIfNCF';
const TYPE = 1;
const FILE_ID = 'DSFhGSmZXeXV5bldY';
const TYPE = 2;

function main() {
convertTencentFileId({
Expand Down
8 changes: 5 additions & 3 deletions script/trial/tencent-doc/sheet-v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ async function main() {
openId: OPEN_ID,

bookId: '300000000$HDrklTrCLcjw',
// bookId: '300000000$HXFJfWyuynWX',
requests: [
{
// addSheetRequest: {
// title: 'test',
// },
updateRangeRequest: {
sheetId: 'hjvlvz',
sheetId: 'ndem2e',
// sheetId: 'MjLh7J',
gridData: {
startRow: 0,
startColumn: 0,
startRow: 8,
startColumn: 4,
rows: [
{
values: [
Expand Down
4 changes: 3 additions & 1 deletion script/trial/tencent-doc/update-sheet-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ async function main() {
openId: OPEN_ID,

bookId: '300000000$HDrklTrCLcjw',
range: 'BB08J2!B16:C16',
// bookId: '300000000$HXFJfWyuynWX',
// range: 'BB08J2!B16:C16',
range: 'ndem2e!B16:C16',
values: [['123', '123123']],
});
console.log('result', result);
Expand Down
29 changes: 20 additions & 9 deletions src/devops/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const OVER_TIME_CONFIG_LIST = [
label: '20分钟',
value: 20 * 60 * 1000,
},
{
label: '10分钟',
value: 10 * 60 * 1000,
},
// {
// label: '10分钟',
// value: 10 * 60 * 1000,
// },
// for test
// {
// label: '1分钟',
Expand Down Expand Up @@ -177,7 +177,11 @@ export async function getAllPipelineList(
}


function findRunningTooLongPipelines(list: Array<any>, time: number, maxTime: number) {
function findRunningTooLongPipelines(
list: Array<any>,
time: number,
maxTime: number,
) {
const res = list
.filter(item => item.latestBuildStatus === 'RUNNING')
.filter((item) => {
Expand All @@ -189,7 +193,12 @@ function findRunningTooLongPipelines(list: Array<any>, time: number, maxTime: nu
}


function genRobotMessage(dataList: Array<any>, host: string, projectId: string) {
function genRobotMessage(
dataList: Array<any>,
host: string,
projectId: string,
overTimeConfigList: typeof OVER_TIME_CONFIG_LIST,
) {
const list = [
`【流水线执行时间过长监控】${timeStampFormat(Date.now(), 'yyyy-MM-dd hh:mm:ss')}<@guowangyang>`,
];
Expand All @@ -200,8 +209,8 @@ function genRobotMessage(dataList: Array<any>, host: string, projectId: string)
const overtimePipelines: Array<any> = [];

// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0;i < OVER_TIME_CONFIG_LIST.length;i++) {
const item = OVER_TIME_CONFIG_LIST[i];
for (let i = 0;i < overTimeConfigList.length;i++) {
const item = overTimeConfigList[i];
const pipelines = findRunningTooLongPipelines(dataList, item.value, maxTime);
overtimePipelines.push(...pipelines);

Expand Down Expand Up @@ -237,15 +246,17 @@ export async function sendOverTimePipelineMessage({
pipelineHost,
webhookUrl,
chatId,
overTimeConfigList = OVER_TIME_CONFIG_LIST,
}: {
params: any;
pipelineHost: string;
webhookUrl: string;
chatId: Array<string>;
overTimeConfigList?: Array<{label: string, value: number}>;
}) {
const pipelineList = await getAllPipelineList(params);

const res = genRobotMessage(pipelineList, pipelineHost, params.projectId);
const res = genRobotMessage(pipelineList, pipelineHost, params.projectId, overTimeConfigList);
let { message } = res;
const { overtimePipelines } = res;

Expand Down
4 changes: 2 additions & 2 deletions src/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { IGitCommitInfo } from './types';
*
* @example
*
* getBranch()
* getGitCurBranch()
*
* // => master
*/
Expand All @@ -25,7 +25,7 @@ export function getGitCurBranch(root?: string) {
*
* @example
* ```ts
* getGitCommitInfo()
* getGitCommitMessage()
* // '优化一部分文档'
* ```
*/
Expand Down
5 changes: 5 additions & 0 deletions src/mp-ci/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ export {
flattenSubPackages,
} from './helper';
export { MpCI } from './mp-ci';

export { updateQQMpResultToSheetV0 } from './mp-sheet-v0';
export { updateQQMpResultToSheet } from './mp-sheet';


export { mpUploadAndReport, mpUploadAndReportByOptions } from './mp-upload-and-report';
export { writeEnvAndPrivateKey, writeEnvAndPrivateKeyByOptions } from './write-env-and-private-key';
100 changes: 100 additions & 0 deletions src/mp-ci/mp-sheet-v0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { uploadTencentDocImage } from '../tencent-doc/tencent-doc';
import { updateTencentSheetImage, updateTencentSheet } from '../tencent-doc/sheet';
import type { ISecretInfo } from '../tencent-doc/types';


export async function updateQQMpResultToSheetV0({
accessToken,
clientId,
openId,

bookId,
sheetId,

startRow,

qqMpQRCodePath,
result,
}: ISecretInfo & {

bookId: string;
sheetId: string;

startRow: number;
startColumn?: number;

qqMpQRCodePath: string;
result: Record<string, any>;
}) {
const uploadImageResult = await uploadTencentDocImage({
accessToken,
clientId,
openId,
image: qqMpQRCodePath,
});

console.log('[CI] upload image result: ', uploadImageResult);

if (uploadImageResult?.ret != 0) {
return uploadImageResult;
}

const updateImageResult = await updateTencentSheetImage({
accessToken,
clientId,
openId,
bookId,
insertImages: {
sheetID: sheetId,
images: [
{
type: 1,
imageID: uploadImageResult.data.imageID,
width: 100,
height: 100,
row: startRow,
col: 1,
offsetX: null,
offsetY: null,
clip_info: null,
},
],
},
});

console.log('[CI] update sheet image result: ', updateImageResult);

if (updateImageResult?.ret != 0) {
return updateImageResult;
}

const {
time,
branch,
env,
robot,
version,
lastCommit,
link,
} = result;
const updateTextResult = await updateTencentSheet({
accessToken,
clientId,
openId,
bookId,
range: `${sheetId}!B${startRow}:H${startRow}`,
values: [[
time,
branch,
env,
robot,
version,
lastCommit,
link,
]],

});
console.log('[CI] update sheet text result: ', updateTextResult);

return updateTextResult;
}
Loading

0 comments on commit 67ecdd7

Please sign in to comment.