Skip to content

Commit

Permalink
Add mirror functionality to repositories service
Browse files Browse the repository at this point in the history
  • Loading branch information
FLYBYME committed Feb 2, 2024
1 parent ee47aa9 commit 3a94781
Show file tree
Hide file tree
Showing 2 changed files with 219 additions and 0 deletions.
109 changes: 109 additions & 0 deletions services/actions.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const DbService = require("db-mixin");
const Membership = require("membership-mixin");
const ConfigLoader = require("config-mixin");
const { MoleculerClientError } = require("moleculer").Errors;


/**
* this is the git.actions service for tracking actions
*/

module.exports = {
// name of service
name: "git.actions",
// version of service
version: 1,

/**
* Service Mixins
*
* @type {Array}
* @property {DbService} DbService - Database mixin
* @property {ConfigLoader} ConfigLoader - Config loader mixin
*/
mixins: [
DbService({}),
ConfigLoader([
'git.**'
]),
],

/**
* Service dependencies
*/
dependencies: [],

/**
* Service settings
*
* @type {Object}
*/
settings: {
rest: true,

fields: {


// inject dbservice fields
...DbService.FIELDS,// inject dbservice fields
},
defaultPopulates: [],

scopes: {
...DbService.SCOPE,
},

defaultScopes: [
...DbService.DSCOPE,
],

// default init config settings
config: {

}
},

/**
* service actions
*/
actions: {

},

/**
* service events
*/
events: {

},

/**
* service methods
*/
methods: {

},


/**
* service created lifecycle event handler
*/
created() {

},

/**
* service started lifecycle event handler
*/
async started() {

},

/**
* service stopped lifecycle event handler
*/
async stopped() {

}
};

110 changes: 110 additions & 0 deletions services/repositories.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@ module.exports = {
},
},

// push pull mirror array
mirrors: {
type: "array",
items: {
type: "object",
props: {
url: {
type: "string",
required: true,
},
type: {
type: "string",
enum: ["push", "pull", "mirror"],
required: true,
default: "mirror",
},
},
required: false,
},
required: false,
default: [],
},

// repository tags
tags: {
Expand Down Expand Up @@ -422,6 +444,94 @@ module.exports = {
}
},

/**
* add mirror to repository
*
* @actions
* @param {String} id - id of repository
* @param {String} url - mirror url
* @param {String} type - mirror type
*
* @returns {Object} - repository object
*/
addMirror: {
params: {
id: {
type: "string",
required: true,
},
url: {
type: "string",
required: true,
},
type: {
type: "string",
enum: ["push", "pull", "mirror"],
required: true,
default: "mirror",
},
},
async handler(ctx) {
const params = Object.assign({}, ctx.params);

// get repository
const repository = await this.getById(ctx, params.id);

// check repository exists
if (!repository) {
throw new MoleculerClientError("repository not found", 404);
}

// add mirror to repository
return this.updateEntity(ctx, {
id: repository.id,
mirrors: [...repository.mirrors, {
url: params.url,
type: params.type
}]
});
}
},

/**
* remove mirror from repository
*
* @actions
* @param {String} id - id of repository
* @param {String} url - mirror url
*
* @returns {Object} - repository object
*/
removeMirror: {
params: {
id: {
type: "string",
required: true,
},
url: {
type: "string",
required: true,
},
},
async handler(ctx) {
const params = Object.assign({}, ctx.params);

// get repository
const repository = await this.getById(ctx, params.id);

// check repository exists
if (!repository) {
throw new MoleculerClientError("repository not found", 404);
}

// remove mirror from repository
return this.updateEntity(ctx, {
id: repository.id,
mirrors: repository.mirrors.filter(mirror => mirror.url !== params.url)
});
}
},

/**
* get repository path
*
Expand Down

0 comments on commit 3a94781

Please sign in to comment.