or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

changelog-generation.mdconfiguration.mdgit-operations.mdgithub-integration.mdindex.mdrepository-analysis.mdversion-management.md
tile.json

repository-analysis.mddocs/

Repository Analysis

Repository provider detection and URL parsing with support for GitHub, GitLab, Bitbucket, and self-hosted instances. This module provides intelligent repository configuration resolution and reference formatting for multiple git hosting providers.

Capabilities

Get Repository Configuration

Parses repository URLs and determines provider-specific settings.

/**
 * Parse repository URL into structured configuration
 * @param repoUrl - Repository URL in various formats
 * @returns Repository configuration with provider and metadata
 */
function getRepoConfig(repoUrl?: string): RepoConfig;

Usage Examples:

import { getRepoConfig } from "changelogen";

// GitHub URLs
const github1 = getRepoConfig("user/repo");
const github2 = getRepoConfig("https://github.com/user/repo");
const github3 = getRepoConfig("git@github.com:user/repo.git");

console.log(github1);
// { provider: "github", repo: "user/repo", domain: "github.com" }

// GitLab URLs
const gitlab = getRepoConfig("https://gitlab.com/user/repo");
// { provider: "gitlab", repo: "user/repo", domain: "gitlab.com" }

// Bitbucket URLs  
const bitbucket = getRepoConfig("https://bitbucket.org/user/repo");
// { provider: "bitbucket", repo: "user/repo", domain: "bitbucket.org" }

// Self-hosted instances
const selfhosted = getRepoConfig("https://git.company.com/user/repo");
// { repo: "user/repo", domain: "git.company.com" }

Resolve Repository Configuration

Automatically resolves repository configuration from project context.

/**
 * Resolve repository configuration from package.json and git remote
 * @param cwd - Working directory to search for configuration
 * @returns Promise resolving to repository configuration or undefined if not found
 */
function resolveRepoConfig(cwd: string): Promise<RepoConfig | undefined>;

Usage Examples:

import { resolveRepoConfig } from "changelogen";

// Auto-resolve from current project
const config = await resolveRepoConfig(process.cwd());

// Resolve from specific directory
const repoConfig = await resolveRepoConfig("/path/to/git/repo");

console.log(config);
// { provider: "github", repo: "user/project", domain: "github.com" }

Resolution Sources (in order of precedence):

  1. package.json repository field:

    {
      "repository": "user/repo",
      "repository": {
        "type": "git", 
        "url": "https://github.com/user/repo.git"
      }
    }
  2. Git remote origin URL:

    git remote get-url origin

Format References

Formats git references as provider-specific links.

/**
 * Format reference as a provider-specific link
 * @param ref - Reference object with type and value
 * @param repo - Repository configuration for link generation
 * @returns Formatted reference string (plain text or markdown link)
 */
function formatReference(ref: Reference, repo?: RepoConfig): string;

Usage Examples:

import { formatReference, getRepoConfig } from "changelogen";

const repo = getRepoConfig("user/repo");

// Hash references
const hashRef = formatReference(
  { type: "hash", value: "abc123" }, 
  repo
);
// Result: "[abc123](https://github.com/user/repo/commit/abc123)"

// Issue references
const issueRef = formatReference(
  { type: "issue", value: "#123" },
  repo
);
// Result: "[#123](https://github.com/user/repo/issues/123)"

// Pull request references
const prRef = formatReference(
  { type: "pull-request", value: "#456" },
  repo
);
// Result: "[#456](https://github.com/user/repo/pull/456)"

// Without repository config (fallback to plain text)
const plainRef = formatReference({ type: "hash", value: "abc123" });
// Result: "abc123"

Format Compare Changes

Generates provider-specific compare/diff URLs.

/**
 * Format compare changes link for repository provider
 * @param v - Version or commit reference
 * @param config - Resolved changelog configuration
 * @returns Markdown link to compare changes
 */
function formatCompareChanges(
  v: string,
  config: ResolvedChangelogConfig
): string;

Usage Examples:

import { formatCompareChanges } from "changelogen";

const compareLink = formatCompareChanges("v1.2.0", config);

// GitHub: "[compare changes](https://github.com/user/repo/compare/v1.1.0...v1.2.0)"
// GitLab: "[compare changes](https://gitlab.com/user/repo/compare/v1.1.0...v1.2.0)"
// Bitbucket: "[compare changes](https://bitbucket.org/user/repo/branches/compare/v1.2.0%0Dv1.1.0)"

Supported Providers

GitHub

Supported URL formats:

  • user/repo (shorthand)
  • github:user/repo
  • https://github.com/user/repo
  • https://github.com/user/repo.git
  • git@github.com:user/repo.git

Reference formats:

  • Hash: /commit/{hash}
  • Issue: /issues/{number}
  • Pull Request: /pull/{number}

GitLab

Supported URL formats:

  • gitlab:user/repo
  • https://gitlab.com/user/repo
  • https://gitlab.com/user/repo.git
  • git@gitlab.com:user/repo.git

Reference formats:

  • Hash: /commit/{hash}
  • Issue: /issues/{number}
  • Pull Request: /merge_requests/{number}

Bitbucket

Supported URL formats:

  • bitbucket:user/repo
  • https://bitbucket.org/user/repo
  • https://bitbucket.org/user/repo.git
  • git@bitbucket.org:user/repo.git

Reference formats:

  • Hash: /commit/{hash}
  • Issue: /issues/{number}
  • Pull Request: /pull-requests/{number}

Self-Hosted Instances

Supported for:

  • GitHub Enterprise
  • GitLab self-hosted
  • Custom git hosting solutions

URL format:

  • https://git.company.com/user/repo
  • git@git.company.com:user/repo.git

Note: Self-hosted instances fall back to plain text references unless provider is explicitly configured.

Repository Configuration Types

type RepoProvider = "github" | "gitlab" | "bitbucket";

interface RepoConfig {
  /** Repository domain (e.g., "github.com", "gitlab.company.com") */
  domain?: string;
  
  /** Repository path (e.g., "user/repository") */
  repo?: string;
  
  /** Detected or configured provider */
  provider?: RepoProvider;
  
  /** Authentication token for API access */
  token?: string;
}

interface Reference {
  /** Type of reference */
  type: "hash" | "issue" | "pull-request";
  
  /** Reference value (commit hash, issue number, etc.) */
  value: string;
}

Provider Detection Logic

URL Parsing

Repository URLs are parsed using flexible regex patterns:

// Supports various formats:
// - SSH: git@domain:user/repo.git
// - HTTPS: https://domain/user/repo(.git)
// - Provider shortcuts: provider:user/repo
// - Shorthand: user/repo (assumes GitHub)

Domain Mapping

Provider detection based on domain:

const domainToProvider = {
  "github.com": "github",
  "gitlab.com": "gitlab", 
  "bitbucket.org": "bitbucket"
};

Fallback Behavior

When provider cannot be determined:

  • Domain is preserved for URL generation
  • Provider-specific features are disabled
  • References fall back to plain text format

Integration Examples

Complete Workflow

import { 
  resolveRepoConfig,
  formatReference,
  formatCompareChanges,
  loadChangelogConfig 
} from "changelogen";

// Auto-resolve repository
const repoConfig = await resolveRepoConfig(process.cwd());
console.log(`Detected ${repoConfig.provider} repository: ${repoConfig.repo}`);

// Load configuration with repository
const config = await loadChangelogConfig(process.cwd(), {
  repo: repoConfig
});

// Format references in changelog
const references = [
  { type: "hash", value: "abc123" },
  { type: "issue", value: "#456" },
  { type: "pull-request", value: "#789" }
];

references.forEach(ref => {
  const formatted = formatReference(ref, config.repo);
  console.log(`${ref.type}: ${formatted}`);
});

// Generate compare link
const compareUrl = formatCompareChanges("v1.2.0", config);
console.log(`Compare: ${compareUrl}`);

Custom Provider Configuration

import { getRepoConfig } from "changelogen";

// Configure custom GitHub Enterprise
const enterpriseRepo = getRepoConfig("https://github.company.com/team/project");
// Manual provider override needed for enterprise instances

const customConfig = {
  ...enterpriseRepo,
  provider: "github" as const,
  token: process.env.GITHUB_ENTERPRISE_TOKEN
};

Error Handling

Repository analysis handles various edge cases:

  • Invalid URLs: Returns partial configuration with available information
  • Missing git remote: Gracefully handles repositories without remotes
  • Network errors: Git command failures are caught and handled
  • Permission issues: File system permission errors are handled gracefully
  • Ambiguous formats: Uses heuristics to determine most likely configuration

Example Error Handling:

import { resolveRepoConfig } from "changelogen";

try {
  const config = await resolveRepoConfig("/path/to/repo");
  
  if (!config.repo) {
    console.log("Could not determine repository - using defaults");
  }
  
  if (!config.provider) {
    console.log("Unknown provider - references will be plain text");
  }
} catch (error) {
  console.error("Failed to resolve repository config:", error.message);
  // Fallback to manual configuration
}