Skip to content

Fix images and pipelines #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions lib/interface/cli/commands/pipeline/get.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,12 @@ const command = new Command({

let pipelines;
// TODO:need to decide for one way for error handeling
if (id && repoOwner && repoName) {
pipelines = await pipeline.getPipelineByNameAndRepo(id, repoOwner, repoName);
} else if (id) {
if (id) {
pipelines = await pipeline.getPipelineById(id);
} else if (repoOwner && repoName) {
pipelines = await pipeline.getAllByRepo({
repoOwner,
repoName,
name,
limit,
page,
});
} else {
pipelines = await pipeline.getAll({
repoOwner,
repoName,
name,
limit,
page,
Expand Down
6 changes: 5 additions & 1 deletion lib/logic/api/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ const getAll = async (options) => {
let addedCfCrTag = false;
_.forEach(image.tags, (tag) => {
// in case we are filtering by registries, ignore the image if it is not from the registires list
if ((options.filterRegistries && options.filterRegistries.indexOf(tag.registry) === -1) || _.isEqual(tag.tag, 'volume')) {
if (options.filterRegistries && options.filterRegistries.indexOf(tag.registry) === -1) {
return;
}
if (_.isEqual(tag.tag, 'volume')) {
addedCfCrTag = true;
return;
}
if (DEFAULTS.CODEFRESH_REGISTRIES.indexOf(tag.registry) !== -1) {
Expand Down
61 changes: 2 additions & 59 deletions lib/logic/api/pipeline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const _ = require('lodash');
const CFError = require('cf-errors');
const { sendHttpRequest } = require('./helper');
const Pipeline = require('../entities/Pipeline');

Expand All @@ -18,6 +17,8 @@ const getAll = async (options) => {
name: options.name,
limit: options.limit,
page: options.page - 1,
repoOwner: options.repoOwner,
repoName: options.repoName,
};
const RequestOptions = {
url: '/api/pipelines',
Expand All @@ -36,62 +37,6 @@ const getAll = async (options) => {
return pipelines;
};

/**
* will return all pipelines by repository owner/name
* @param repoOwner
* @param repoName
* @returns {Promise<*>}
*/
const getAllByRepo = async (options) => {
const qs = {
name: options.name,
limit: options.limit,
page: options.page - 1,
};
const RequestOptions = {
url: `/api/services/${encodeURIComponent(options.repoOwner)}/${encodeURIComponent(options.repoName)}`,
qs,
method: 'GET',
};

const result = await sendHttpRequest(RequestOptions);
const pipelines = [];

_.forEach(result, (pipeline) => {
const data = _extractFieldsForPipelineEntity(pipeline);
pipelines.push(new Pipeline(data));
});

return pipelines;

/* TODO:ask itai about this issue
_.forEach(pipelines, (pipeline) => {
delete pipeline.account;
});
return pipelines;
*/
};

/**
* will a pipeline by its name and repository owner/name
* @param name
* @param repoOwner
* @param repoName
* @returns {Promise<*>}
*/
const getPipelineByNameAndRepo = async (name, repoOwner, repoName) => {
const pipelines = await getAllByRepo({
repoOwner,
repoName,
});
const currPipeline = _.find(pipelines, pipeline => pipeline.info.name.toString() === name);

if (!currPipeline) {
throw new CFError(`Pipeline name: ${name} wasn't found under repository: ${repoOwner}/${repoName}`);
} else {
return currPipeline;
}
};

const getPipelineById = async (id) => {
const options = {
Expand Down Expand Up @@ -172,8 +117,6 @@ const patchPipelineByNameAndRepo = async (name, repoOwner, repoName, pipeline) =


module.exports = {
getPipelineByNameAndRepo,
getAllByRepo,
runPipelineById,
patchPipelineById,
patchPipelineByNameAndRepo,
Expand Down