Skip to content
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dev-mainsequence/devtools",
"version": "0.3.17",
"version": "0.3.18",
"description": "Shared MainSequence developer actions, project operations, MCP client and command runner",
"license": "MIT",
"engines": {
Expand Down
13 changes: 11 additions & 2 deletions src/shared/repositoryModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export type GitHubRepositoryBinding = {
code_repository_uid: string;
code_repository_name: string;
repo_name: string;
github_full_name: string;
/** The backend leaves it empty for some bindings; setup clones from `git_ssh_url` and never reads it. */
github_full_name: string | null;
git_ssh_url?: string | null;
git_repo_url?: string | null;
};
Expand All @@ -55,6 +56,14 @@ function requiredObject(value: unknown, label: string): Record<string, any> {
return value as Record<string, any>;
}

/** A label nothing depends on: missing or empty is null, never a reason to refuse the record. */
function optionalLabel(value: unknown, label: string): string | null {
const normalized = typeof value === 'string' ? value.trim() : '';
if (!normalized) return null;
if (/[\r\n]/.test(normalized)) throw new ApiError(`${label} must be a single line.`);
return normalized;
}

function optionalSingleLine(value: unknown, label: string): string | null | undefined {
if (value == null) return value as null | undefined;
return requiredSingleLine(value, label);
Expand Down Expand Up @@ -111,7 +120,7 @@ export function gitHubRepositoryBindingFromResponse(value: unknown, label: strin
code_repository_uid: requiredSingleLine(payload.code_repository_uid, `${label} CodeRepository UID`),
code_repository_name: requiredSingleLine(payload.code_repository_name, `${label} CodeRepository name`),
repo_name: requiredSingleLine(payload.repo_name, `${label} repository name`),
github_full_name: requiredSingleLine(payload.github_full_name, `${label} GitHub full name`),
github_full_name: optionalLabel(payload.github_full_name, `${label} GitHub full name`),
git_ssh_url: optionalSingleLine(payload.git_ssh_url, `${label} SSH URL`),
git_repo_url: optionalSingleLine(payload.git_repo_url, `${label} Git URL`)
};
Expand Down
18 changes: 18 additions & 0 deletions tests/repository-models.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const { gitHubRepositoryBindingFromResponse } = require('../dist/shared/repositoryModels.js');

const binding = { uid: 'binding-1', code_repository_uid: 'repo-1', code_repository_name: 'binance-connectors', repo_name: 'binance-connectors',
git_ssh_url: 'git@github.com:mainsequence-projects/binance-connectors.git', git_repo_url: 'https://github.com/mainsequence-projects/binance-connectors.git' };

test('a GitHub binding without a GitHub full name is still a binding: setup clones from its SSH URL', () => {
for (const github_full_name of ['', ' ', null, undefined]) {
const parsed = gitHubRepositoryBindingFromResponse({ ...binding, github_full_name }, 'GitHub binding');
assert.equal(parsed.github_full_name, null, JSON.stringify(github_full_name));
assert.equal(parsed.git_ssh_url, binding.git_ssh_url);
}
assert.equal(gitHubRepositoryBindingFromResponse({ ...binding, github_full_name: ' mainsequence-projects/binance-connectors ' }, 'GitHub binding').github_full_name,
'mainsequence-projects/binance-connectors');
assert.throws(() => gitHubRepositoryBindingFromResponse({ ...binding, github_full_name: 'a\nb' }, 'GitHub binding'), /GitHub full name must be a single line/);
assert.throws(() => gitHubRepositoryBindingFromResponse({ ...binding, uid: '' }, 'GitHub binding'), /GitHub binding UID is required/);
});
2 changes: 1 addition & 1 deletion tests/setup.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const fetchImpl = async (url, options) => {
let result;
if(endpoint === '/api/v1/code-repositories/repo-1/') result = {uid:'repo-1',code_repository_name:'Shared',code_repository_type:'python',primary_language:'python',framework:'none',github_repository_binding_uid:'binding-1',branches:[{uid:'branch-1',repository_branch:'main'}]};
else if(endpoint === '/api/v1/code-repository-branches/branch-1/') result = {uid:'branch-1',code_repository_uid:'repo-1',code_repository_name:'Shared',repository_branch:'main',github_repository_binding_uid:'binding-1',is_initialized:true};
else if(endpoint === '/api/v1/github-repository-bindings/binding-1/') result = {uid:'binding-1',code_repository_uid:'repo-1',code_repository_name:'Shared',repo_name:'Shared',github_full_name:'Example/Shared',git_ssh_url:'git@github.com:Example/Shared.git'};
else if(endpoint === '/api/v1/github-repository-bindings/binding-1/') result = {uid:'binding-1',code_repository_uid:'repo-1',code_repository_name:'Shared',repo_name:'Shared',github_full_name:'',git_ssh_url:'git@github.com:Example/Shared.git'}; // the backend leaves the name empty for some bindings
else if(endpoint === '/api/v1/users/me/') result = {username:'fixture',organization:{name:'Fixture Org'}};
else if(endpoint === '/api/v1/code-repositories/repo-1/add-deploy-key/') {
const key = JSON.parse(options.body); if(!key.public_key.startsWith('ssh-ed25519 ')) throw Error('invalid fixture key'); result={};
Expand Down
Loading