Move test repo URL to environment
This commit is contained in:
@@ -5,6 +5,9 @@
|
|||||||
GITCODE_USERNAME=你的手机号/用户名/邮箱
|
GITCODE_USERNAME=你的手机号/用户名/邮箱
|
||||||
GITCODE_PASSWORD=你的密码
|
GITCODE_PASSWORD=你的密码
|
||||||
|
|
||||||
|
# 更新项目任务使用的仓库编辑页(必填)
|
||||||
|
GITCODE_TEST_REPO_URL=https://gitcode.com/你的用户名/你的仓库/edit/main/你的文件
|
||||||
|
|
||||||
# 飞书 Webhook(可选,不填则跳过飞书通知)
|
# 飞书 Webhook(可选,不填则跳过飞书通知)
|
||||||
# FEISHU_WEBHOOK=https://open.feishu.cn/open-apis/bot/v2/hook/你的webhook
|
# FEISHU_WEBHOOK=https://open.feishu.cn/open-apis/bot/v2/hook/你的webhook
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const config = {
|
|||||||
// 积分/任务中心页面
|
// 积分/任务中心页面
|
||||||
points: 'https://gitcode.com/setting/points',
|
points: 'https://gitcode.com/setting/points',
|
||||||
// 测试仓库编辑页(更新项目任务用)
|
// 测试仓库编辑页(更新项目任务用)
|
||||||
testRepo: 'https://gitcode.com/fzxlzy/test/edit/main/testjpgp11',
|
testRepo: process.env.GITCODE_TEST_REPO_URL || '',
|
||||||
},
|
},
|
||||||
|
|
||||||
// 登录凭据(优先从环境变量读取,兜底使用默认值)
|
// 登录凭据(优先从环境变量读取,兜底使用默认值)
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ const { safeClose, safeGoto } = require(path.join(__dirname, '..', 'utils', 'pag
|
|||||||
async function updateProject(page) {
|
async function updateProject(page) {
|
||||||
logger.info('👉 执行项目更新');
|
logger.info('👉 执行项目更新');
|
||||||
|
|
||||||
|
if (!config.urls.testRepo) {
|
||||||
|
throw new Error('未配置 GITCODE_TEST_REPO_URL,无法执行更新项目任务');
|
||||||
|
}
|
||||||
|
|
||||||
const context = page.context();
|
const context = page.context();
|
||||||
const newPage = await context.newPage();
|
const newPage = await context.newPage();
|
||||||
|
|
||||||
|
|||||||
24
test.js
24
test.js
@@ -1,6 +1,9 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { chromium } from 'playwright'
|
import { chromium } from 'playwright'
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const browser = await chromium.launch({
|
const browser = await chromium.launch({
|
||||||
@@ -134,11 +137,16 @@ async function taskIsCompleted(task) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function doUpdateProject(page) {
|
async function doUpdateProject(page) {
|
||||||
console.log('👉 执行项目更新');
|
console.log('👉 执行项目更新');
|
||||||
const context = page.context();
|
const testRepoUrl = process.env.GITCODE_TEST_REPO_URL;
|
||||||
const newPage = await context.newPage();
|
if (!testRepoUrl) {
|
||||||
await newPage.goto('https://gitcode.com/fzxlzy/test/edit/main/testjpgp11');
|
throw new Error('未配置 GITCODE_TEST_REPO_URL,无法执行更新项目任务');
|
||||||
|
}
|
||||||
|
|
||||||
|
const context = page.context();
|
||||||
|
const newPage = await context.newPage();
|
||||||
|
await newPage.goto(testRepoUrl);
|
||||||
// 你可以自己补逻辑
|
// 你可以自己补逻辑
|
||||||
const frame = newPage.frameLocator('#codeartside');
|
const frame = newPage.frameLocator('#codeartside');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user