-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"id": 100001, | ||
"iid": 2, | ||
"project_id": 100001, | ||
"title": "For *** Test New", | ||
"description": "test", | ||
"state": "opened", | ||
"created_at": "2024-01-02T02:27:57.658Z", | ||
"updated_at": "2024-01-15T08:06:48.811Z", | ||
"closed_at": null, | ||
"closed_by": null, | ||
"labels": [], | ||
"milestone": null, | ||
"assignees": [], | ||
"author": { | ||
"id": 100001, | ||
"username": "***", | ||
"name": "***", | ||
"state": "active", | ||
"locked": false, | ||
"avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/***/avatar.png", | ||
"web_url": "https://gitlab.com/***" | ||
}, | ||
"type": "ISSUE", | ||
"assignee": null, | ||
"user_notes_count": 1, | ||
"merge_requests_count": 0, | ||
"upvotes": 0, | ||
"downvotes": 0, | ||
"due_date": null, | ||
"confidential": false, | ||
"discussion_locked": null, | ||
"issue_type": "issue", | ||
"web_url": "https://gitlab.com/***/***/-/issues/2", | ||
"time_stats": { | ||
"time_estimate": 0, | ||
"total_time_spent": 0, | ||
"human_time_estimate": null, | ||
"human_total_time_spent": null | ||
}, | ||
"task_completion_status": { | ||
"count": 0, | ||
"completed_count": 0 | ||
}, | ||
"blocking_issues_count": 0, | ||
"has_tasks": true, | ||
"task_status": "0 of 0 checklist items completed", | ||
"_links": { | ||
"self": "https://gitlab.com/api/v4/projects/***/issues/2", | ||
"notes": "https://gitlab.com/api/v4/projects/***/issues/2/notes", | ||
"award_emoji": "https://gitlab.com/api/v4/projects/***/issues/2/award_emoji", | ||
"project": "https://gitlab.com/api/v4/projects/***", | ||
"closed_as_duplicate_of": null | ||
}, | ||
"references": { | ||
"short": "#2", | ||
"relative": "#2", | ||
"full": "***/***#2" | ||
}, | ||
"severity": "UNKNOWN", | ||
"subscribed": true, | ||
"moved_to_id": null, | ||
"service_desk_reply_to": null | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import dayjs from "dayjs"; | ||
import { GITLAB_NUMBER, GITLAB_PROJECT_ID, mock, readJSONSync, writeJSONSync } from "../helper/helper"; | ||
|
||
const filename = "temp-gitlab.json"; | ||
|
||
export async function initGitlabJSONFile() { | ||
writeJSONSync(filename, []); | ||
} | ||
|
||
export async function mockGitlabFind() { | ||
mock?.onGet(`https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/issues/${GITLAB_NUMBER}/notes`).reply(async (config) => { | ||
const result = readJSONSync(filename); | ||
if (config.params?.since) { | ||
return [200, result.filter((item: any) => dayjs(item.created_at).isAfter(dayjs(config.params.since)))]; | ||
} | ||
if (config.params?.page && config.params?.per_page) { | ||
const start = (config.params.page - 1) * config.params.per_page; | ||
const end = config.params.page * config.params.per_page; | ||
return [200, result.slice(start, end)]; | ||
} | ||
return [200, result]; | ||
}); | ||
} | ||
|
||
export async function mockGitlabFindById() { | ||
mock?.onGet(new RegExp(`https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/issues/${GITLAB_NUMBER}/notes/\\d+`)).reply(async (config) => { | ||
Check failure Code scanning / CodeQL Regular expression injection High test
This regular expression is constructed from a
environment variable Error loading related location Loading This regular expression is constructed from a environment variable Error loading related location Loading |
||
const result = readJSONSync(filename); | ||
const id = config.url?.match(/\/notes\/(\d+)/)?.[1]; | ||
const target = result.find((item: any) => item.id == id); | ||
if (!target) { | ||
return [404, { | ||
"message": "404 Not found" | ||
}]; | ||
} | ||
return [200, target]; | ||
}); | ||
} | ||
|
||
export async function mockGitlabCreate() { | ||
mock?.onPost(`https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/issues/${GITLAB_NUMBER}/notes`).reply(async (config) => { | ||
const result = readJSONSync(filename); | ||
const data = { | ||
id: Math.round(Math.random() * 1000000), | ||
body: JSON.parse(config.data).body, | ||
system: false, | ||
author: { | ||
id: 100001, | ||
username: "***", | ||
name: "***", | ||
avatar_url: "https://foruda.gitlab.com/avatar/***/***.png", | ||
}, | ||
created_at: dayjs().format(), | ||
updated_at: dayjs().format() | ||
}; | ||
result.push(data); | ||
writeJSONSync(filename, result); | ||
return [200, data]; | ||
}); | ||
} | ||
|
||
export async function mockGitlabUpdateById() { | ||
mock?.onPut(new RegExp(`https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/issues/${GITLAB_NUMBER}/notes/\\d+`)).reply(async (config) => { | ||
Check failure Code scanning / CodeQL Regular expression injection High test
This regular expression is constructed from a
environment variable Error loading related location Loading This regular expression is constructed from a environment variable Error loading related location Loading |
||
const raw = readJSONSync(filename); | ||
const id = config.url?.match(/\/notes\/(\d+)/)?.[1]; | ||
const target = raw.find((item: any) => item.id == id); | ||
if (!target) { | ||
return [404, { | ||
"message": "404 Not found" | ||
}]; | ||
} | ||
raw.forEach((item: any) => { | ||
if (item.id == id) { | ||
item.body = JSON.parse(config.data).body; | ||
item.updated_at = dayjs().format(); | ||
} | ||
}); | ||
writeJSONSync(filename, raw); | ||
const resAfter = readJSONSync(filename); | ||
return [200, resAfter.find((item: any) => item.id == id)]; | ||
}); | ||
} | ||
|
||
export async function mockGitlabDeleteById() { | ||
mock?.onDelete(new RegExp(`https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/issues/${GITLAB_NUMBER}/notes/\\d+`)).reply(async (config) => { | ||
Check failure Code scanning / CodeQL Regular expression injection High test
This regular expression is constructed from a
environment variable Error loading related location Loading This regular expression is constructed from a environment variable Error loading related location Loading |
||
const raw = readJSONSync(filename); | ||
const id = config.url?.match(/\/notes\/(\d+)/)?.[1]; | ||
const target = raw.find((item: any) => item.id == id); | ||
if (!target) { | ||
return [404, { | ||
"message": "404 Not found" | ||
}]; | ||
} | ||
const remain = raw.find((item: any) => item.id != id); | ||
writeJSONSync(filename, remain ? remain : []); | ||
return [204]; | ||
}); | ||
} | ||
|
||
export async function mockGitlabDetail() { | ||
mock?.onGet(new RegExp(`https://gitlab.com/api/v4/projects/${GITLAB_PROJECT_ID}/issues/${GITLAB_NUMBER}`)).reply(async (config) => { | ||
Check failure Code scanning / CodeQL Regular expression injection High test
This regular expression is constructed from a
environment variable Error loading related location Loading This regular expression is constructed from a environment variable Error loading related location Loading |
||
return [200, readJSONSync('mock-gitlab-detail.json')]; | ||
}); | ||
} |