composer / satis

Simple static Composer repository generator - For a full private Composer repo use Private Packagist

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I prevent Satis from erroring when a repostiory has no `composer.json` present?

JacobDB opened this issue · comments

I'm building a component system for my company, and I've run in to a mildly irritating issue. When I initialize a repository for a component (to house the 'build this component' issue), Satis errors out because it's trying to parse an empty repository.

This is the script I'm using:

#!/bin/bash

# Set headers
echo "Content-type: text/plain"
echo ""

GROUP_ID="<GITLAB-GROUP-ID>"
GITLAB_TOKEN="<GITLAB-API-TOKEN>"
GITLAB_API="https://git.example.com/api/v4"

# Get the list of projects in the group
projects=$(curl --silent --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "$GITLAB_API/groups/$GROUP_ID/projects")

# Extract the required information from the projects response
repositories=$(echo "$projects" | jq -c '[.[] | {type: "vcs", url: .ssh_url_to_repo}]')

# Generate the JSON object
json_object=$(jq -n --argjson repositories "$repositories" '{"name": "example/components", "homepage": "https://packages.example.com", "repositories": $repositories, "require-all": true}')

# Write the Satis config
echo "$json_object" > /var/www/packages.example.com/satis.json

# Set Composer home
export COMPOSER_HOME=/var/www/packages.example.com/composer

# Build
/usr/bin/php /var/www/packages.example.com/html/bin/satis build /var/www/packages.example.com/satis.json /var/www/packages.example.com/html/web

It uses the GitLab API to fetch every repository in our "components" group, then generates the satis.json file using that information. Of course, if one of these repositories is missing a composer.json, it instantly fails. Is there any way to rectify this?

Sounds like you should be scanning for the composer.json file and skip the repo if it is missing. Not having this file means it is unusable for Composer anyways.

Thanks, that's one solution I did consider, I was just hoping to avoid making a ton of API calls every time a build is created. I was hoping there was a way to pass a flag to Satis to ignore invalid repositories.

commented

Had a quick peek at https://docs.gitlab.com/ee/api/groups.html#list-a-groups-projects

My suggestion would be to add a satis topic to the repositories that are considered valid / ready-for-use and simply use that as a selector in your API request.

Although that works on a project level, and it has been ages since I used Gitlab, so I am not sure if a project equals a repository or not.