feat: auto-merge non-breaking dependency updates (#5)
Node.js CI / CI (push) Successful in 24s
Security Scan and Upload / Security & DefectDojo Upload (push) Successful in 1m50s

## Summary
Minori now automatically merges dependency update PRs when they meet safety criteria, reducing manual work whilst maintaining safety for potentially breaking changes.

## Changes
-  Add version comparison utility to detect major version bumps
-  Add Gitea service methods for checking commit status and merging PRs
-  Add auto-merge logic that checks:
  - Is it a major version bump? (if yes, skip auto-merge)
  - Did CI checks pass? (if no, skip auto-merge)
  - If both conditions pass → auto-merge! 🎉
-  Add comprehensive tests for all new functionality
- 📊 Maintain ~94% test coverage

## How It Works
When Minori processes a dependency update:
1. Check if a PR already exists for that dependency
2. If it exists, verify:
   - **Not a major version bump** (major bumps need manual review)
   - **CI status = "success"** (all checks must pass)
3. If both conditions are met → automatically merge the PR and delete the branch

## Test Plan
- [x] All 114 tests passing
- [x] New tests for version comparison utility
- [x] New tests for Gitea service extensions
- [x] Build successful
- [x] Linting clean

---
 This PR was created with help from Hikari~ 🌸

Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com>
Reviewed-on: #5
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
This commit was merged in pull request #5.
This commit is contained in:
2026-02-20 20:04:18 -08:00
committed by Naomi Carrigan
parent 2bb7208bab
commit d9f959d115
10 changed files with 492 additions and 24 deletions
+78
View File
@@ -7,6 +7,7 @@
import axios, { isAxiosError, type AxiosInstance } from "axios";
import { config } from "../config.js";
import type {
GiteaCombinedStatus,
GiteaFile,
GiteaPullRequest,
GiteaRepository,
@@ -142,6 +143,83 @@ class GiteaService {
);
return data;
}
/**
* Gets the combined commit status for a specific commit by querying the Gitea API for all status checks.
* @param owner - The repository owner.
* @param repo - The repository name.
* @param sha - The commit SHA to check.
* @returns The combined status of all checks (pending, success, error, or failure).
*/
public async getCommitStatus(
owner: string,
repo: string,
sha: string,
): Promise<GiteaCombinedStatus> {
const { data } = await this.client.get<GiteaCombinedStatus>(
`/repos/${owner}/${repo}/commits/${sha}/status`,
);
return data;
}
/**
* Merges a pull request.
* @param owner - The repository owner.
* @param repo - The repository name.
* @param index - The pull request index number.
* @returns True if the merge was successful, false otherwise.
*/
public async mergePullRequest(
owner: string,
repo: string,
index: number,
): Promise<boolean> {
try {
await this.client.post(
`/repos/${owner}/${repo}/pulls/${String(index)}/merge`,
{
/* eslint-disable @typescript-eslint/naming-convention -- Gitea API uses snake_case */
Do: "merge",
MergeMessageField: "",
MergeTitleField: "",
delete_branch_after_merge: true,
force_merge: false,
head_commit_id: "",
merge_when_checks_succeed: false,
/* eslint-enable @typescript-eslint/naming-convention -- End Gitea API */
},
);
return true;
} catch (error) {
if (isAxiosError(error)) {
return false;
}
throw error;
}
}
/**
* Deletes a repository branch by name.
* @param owner - The repository owner.
* @param repo - The repository name.
* @param branch - The branch name to remove.
* @returns True if successful, false otherwise.
*/
public async deleteBranch(
owner: string,
repo: string,
branch: string,
): Promise<boolean> {
try {
await this.client.delete(`/repos/${owner}/${repo}/branches/${branch}`);
return true;
} catch (error) {
if (isAxiosError(error)) {
return false;
}
throw error;
}
}
}
export { GiteaService };