Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang committed Dec 18, 2023
1 parent 2f7193f commit 390fe2f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 10 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ GITLAB_CLIENT_SECRET="***"
COVERAGE_DATA_URL=http://s3.xxx
REDIRECT_URI=http://localhost:3000/login

APP_URI=http://localhost:3000
UPLOAD_URL=http://localhost:3000
61 changes: 53 additions & 8 deletions packages/canyon-backend/src/upload/upload.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,76 @@ import {
Query,
Body,
UseInterceptors,
Req,
} from '@nestjs/common';
import { RawBodyMiddleware } from './raw-body.middleware';
import { uploadAnalyze } from './helpers/uploadAnalyze';
import axios from 'axios';
import * as process from 'process';

@Controller('upload')
export class UploadController {
constructor() {}
@Post('v4')
@HttpCode(200)
test(@Query() q, @Body() b) {
console.log(q, b);
test(@Query() q, @Body() b, @Req() req) {
// TODO: 需要一个唯一id在post和put之间传递

// 第一个参数 resultURL
// 第二个参数 putURL
return `${process.env.UPLOAD_URL}/upload/query
${process.env.UPLOAD_URL}/upload/v4?query=1`;
${process.env.UPLOAD_URL}${req.originalUrl}`;
}
@Put('v4')
@HttpCode(200)
@UseInterceptors(RawBodyMiddleware)
test1(@Query() q, @Body() buffer: Buffer) {
const cov = uploadAnalyze(buffer.toString());
console.log(cov, 'cov');
async test1(@Query() query, @Body() buffer: Buffer) {
const { commit, branch, instrument_cwd, slug } = query;
const { coverage } = uploadAnalyze(buffer.toString());
// TODO: 实现转换成canyon的数据结构
return cov;
const projectID = await axios
.get(
`${process.env.GITLAB_URL}/api/v4/projects/${encodeURIComponent(slug)}`,
{
headers: {
// 我自己的token
'PRIVATE-TOKEN': 'dpxTutmZv_wPogCkpCmc',
},
},
)
.then((res) => {
return res.data.id;
});
const url = process.env.APP_URI;
console.log({
branch: branch,
commitSha: commit,
projectID: String(projectID),
instrumentCwd: instrument_cwd,
});
await axios
.post(
`${url}/coverage/client`,
{
branch: branch,
coverage: coverage,
commitSha: commit,
projectID: String(projectID),
instrumentCwd: instrument_cwd,
},
{
headers: {
Authorization: `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InR6aGFuZ20iLCJpZCI6ODQxNywiaWF0IjoxNzAxODUxNTQ1LCJleHAiOjIwMTc0Mjc1NDV9.Bx8pYLNP9XlmrPDlHNCz_M1A-VoEbhTx0njYyTr9n6Y`,
},
},
)
.then((res) => {
console.log(res.data.message);
});
console.log('上传成功...');
await axios.post(`${url}/coverage/triggeragg`, {
reportID: commit,
});
console.log('触发聚合...');
return 'ok';
}
}
2 changes: 1 addition & 1 deletion packages/canyon-cli/src/helpers/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export async function uploadToCanyonPOST(
* @param {Object} queryParams
* @returns {string}
*/
export function generateQuery(queryParams: Partial<IServiceParams>): string {
export function generateQuery(queryParams: Partial<IServiceParams & {instrumentCwd:string}>): string {
return new URLSearchParams(
Object.entries(queryParams).map(([key, value]) => [snakeCase(key), value]),
).toString()
Expand Down
5 changes: 4 additions & 1 deletion packages/canyon-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,10 @@ export async function main(
}
}

const query = webHelpers.generateQuery(buildParams)
const query = webHelpers.generateQuery({
...buildParams,
instrumentCwd: projectRoot,
})

if (args.dryRun) {
dryRun(uploadHost, token, query, uploadFile.toString(), args.source || '')
Expand Down

0 comments on commit 390fe2f

Please sign in to comment.