Commit 46d0c0bc authored by 智勇's avatar 智勇

优化获取分支

parent 220b9128
...@@ -148,7 +148,7 @@ const gitBranch = async (svcName) => { ...@@ -148,7 +148,7 @@ const gitBranch = async (svcName) => {
const version = proConfig.git_lab === 'gitabc.xyqb.com' ? 'v3' : 'v4' const version = proConfig.git_lab === 'gitabc.xyqb.com' ? 'v3' : 'v4'
const token = config.gitlab.token const token = config.gitlab.token
const data = await awaitRequest({ const data = await awaitRequest({
url: `http://${proConfig.git_lab}/api/${version}/projects?per_page=200&search=${svcName}&private_token=${token}`, url: `http://${proConfig.git_lab}/api/${version}/projects?per_page=200&search=${svcName}&private_token=${token}&simple=true`,
method: 'GET', method: 'GET',
}) })
if (data.length === 0) { if (data.length === 0) {
...@@ -170,7 +170,7 @@ const gitBranch = async (svcName) => { ...@@ -170,7 +170,7 @@ const gitBranch = async (svcName) => {
} }
const getGitBranch = async function (ctx) { const getGitBranch = async function (ctx) {
const { name } = ctx.request.body const { name } = ctx.request.query
const branchInfo = await gitBranch(name) const branchInfo = await gitBranch(name)
if (branchInfo.length === 0) { if (branchInfo.length === 0) {
ctx.body = ctx.fail('无拉去此项目的权限') ctx.body = ctx.fail('无拉去此项目的权限')
...@@ -334,7 +334,7 @@ const router = new Router() ...@@ -334,7 +334,7 @@ const router = new Router()
router router
.use(bodyParser()) .use(bodyParser())
.post('/save', save) .post('/save', save)
.post('/master', getGitBranch) .get('/getGitBranch', getGitBranch)
.post('/find', findPipes) .post('/find', findPipes)
.post('/webhooks', webhooks) .post('/webhooks', webhooks)
.post('/delete', deletePipes) .post('/delete', deletePipes)
......
...@@ -14,7 +14,6 @@ const schema = new Schema({ ...@@ -14,7 +14,6 @@ const schema = new Schema({
noticeAddress: { type: String }, noticeAddress: { type: String },
noticeType: { type: String }, noticeType: { type: String },
update_user: { type: String }, update_user: { type: String },
create_time: { type: String },
des: { type: String }, des: { type: String },
}, { }, {
versionKey: false, versionKey: false,
...@@ -23,6 +22,7 @@ const schema = new Schema({ ...@@ -23,6 +22,7 @@ const schema = new Schema({
}) })
schema.statics.savePipes = function (doc) { schema.statics.savePipes = function (doc) {
if (doc._id) { if (doc._id) {
delete doc.updatedAt
return this.updateOne({ return this.updateOne({
_id: doc._id, _id: doc._id,
}, doc) }, doc)
...@@ -32,10 +32,10 @@ schema.statics.savePipes = function (doc) { ...@@ -32,10 +32,10 @@ schema.statics.savePipes = function (doc) {
schema.statics.getPipes = function (data) { schema.statics.getPipes = function (data) {
data.application_name = new RegExp(data.application_name) data.application_name = new RegExp(data.application_name)
data.new_user = new RegExp(data.new_user) data.new_user = new RegExp(data.new_user)
return this.find(data).sort({ createdAt: -1 }) return this.find(data).sort({ updatedAt: -1 })
} }
schema.statics.getMatchPipe = function (name) { schema.statics.getMatchPipe = function (name) {
return this.find({ repos: { $elemMatch: { repository: name } } }).sort({ createdAt: 1 }) return this.find({ repos: { $elemMatch: { repository: name } } }).sort({ updatedAt: 1 })
} }
schema.statics.delete = function (id) { schema.statics.delete = function (id) {
return this.findByIdAndRemove(id) return this.findByIdAndRemove(id)
......
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