Skip to content
Open
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
47 changes: 29 additions & 18 deletions src/chameleon_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import GreptileAPI from './greptile'
interface ChangelogConfig {
owner: string
repo: string
startDate: Date
endDate: Date
startDate?: Date // Optional when using SHA-based selection
endDate?: Date // Optional when using SHA-based selection
baseSha?: string // Direct SHA for base (pre state)
headSha?: string // Direct SHA for head (post state)
customInstructions: string
}

Expand All @@ -19,14 +21,18 @@ class ChangelogGenerator {
}

async generateChangelog(config: ChangelogConfig): Promise<string> {
const { owner, repo, startDate, endDate, customInstructions } = config;

// Get commits between dates
const { owner, repo, startDate, endDate, baseSha, headSha, customInstructions } = config;

// Determine base and head SHAs - use direct SHAs if provided, otherwise convert from dates
const base = baseSha ?? await this.getCommitFromDate(owner, repo, startDate!)
const head = headSha ?? await this.getCommitFromDate(owner, repo, endDate!)

// Get commits between the two points
const commits = await this.octokit.repos.compareCommits({
owner,
repo,
base: await this.getCommitFromDate(owner, repo, startDate),
head: await this.getCommitFromDate(owner, repo, endDate),
base,
head,
})

// Index repository in Greptile
Expand All @@ -38,31 +44,36 @@ class ChangelogGenerator {

// Check if there are any changes before making the API call
const noChangesFound = !commits.data.files || commits.data.files.length === 0;


// Build version range description based on whether dates or SHAs were provided
const versionRange = startDate && endDate
? `Time period: From ${startDate.toISOString()} to ${endDate.toISOString()}`
: `Commits: From ${base.substring(0, 7)} to ${head.substring(0, 7)}`;

// Construct the prompt based on whether changes were found
let prompt: string;

if (noChangesFound) {
prompt = `
Generate a changelog for the following repository: ${owner}/${repo}
Time period: From ${startDate.toISOString()} to ${endDate.toISOString()}
${versionRange}

${customInstructions || "Generate a user-friendly changelog in markdown format."}

There are NO CHANGES found in this repository during the specified time period.
There are NO CHANGES found in this repository during the specified version range.
Please generate a message indicating that no changes were found.

Your response should follow this format:
${customInstructions?.includes('mintlify')
${customInstructions?.includes('mintlify')
? `<Update label="${new Date().toISOString().split('T')[0]}" description="No Changes">
- No code changes were found in the repository during the specified time period.
- This could be due to no commits being made or the selected date range not containing any activity.
- No code changes were found in the repository during the specified version range.
- This could be due to no commits being made or the selected range not containing any activity.
</Update>`
: `## No Changes Found

- No code changes were found in the repository during the specified time period.
- This could be due to no commits being made or the selected date range not containing any activity.
- Try selecting a different date range or repository to view changes.
- No code changes were found in the repository during the specified version range.
- This could be due to no commits being made or the selected range not containing any activity.
- Try selecting a different range or repository to view changes.

*Generated on ${new Date().toLocaleString()}*`
}
Expand All @@ -73,7 +84,7 @@ Do not include any explanations outside of this format. Only return the formatte
// Normal case with changes
prompt = `
Generate a changelog for the following repository: ${owner}/${repo}
Time period: From ${startDate.toISOString()} to ${endDate.toISOString()}
${versionRange}

${customInstructions || "Generate a user-friendly changelog in markdown format."}

Expand Down
Loading