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
+79 -4
View File
@@ -6,11 +6,16 @@
/* eslint-disable vitest/valid-expect -- Test expectations don't need messages */
/* eslint-disable max-lines-per-function -- Test suites require many test cases */
/* eslint-disable max-lines -- Test suites naturally have many cases */
/* eslint-disable max-statements -- Test suites naturally have many statements */
/* eslint-disable @typescript-eslint/consistent-type-assertions -- Required for mocking */
/* eslint-disable @typescript-eslint/consistent-type-imports -- Dynamic imports */
/* eslint-disable @typescript-eslint/naming-convention -- Environment variables and Gitea API format */
/* eslint-disable max-nested-callbacks -- Vitest structure requires nested callbacks */
/* eslint-disable vitest/require-to-throw-message -- Generic throw assertion */
/* eslint-disable vitest/prefer-to-be-truthy -- toBe(true) is clearer for boolean functions */
/* eslint-disable vitest/prefer-to-be-falsy -- toBe(false) is clearer for boolean functions */
/* eslint-disable stylistic/max-len -- Test files have long object literals */
import axios, { AxiosError, type AxiosResponse } from "axios";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
@@ -24,8 +29,9 @@ vi.mock("axios", async() => {
default: {
create: vi.fn(() => {
return {
get: vi.fn(),
post: vi.fn(),
delete: vi.fn(),
get: vi.fn(),
post: vi.fn(),
};
}),
},
@@ -69,6 +75,8 @@ describe("giteaService", () => {
let mockGet: ReturnType<typeof vi.fn>;
// eslint-disable-next-line @typescript-eslint/init-declarations -- Reassigned in beforeEach
let mockPost: ReturnType<typeof vi.fn>;
// eslint-disable-next-line @typescript-eslint/init-declarations -- Reassigned in beforeEach
let mockDelete: ReturnType<typeof vi.fn>;
const originalEnvironment = process.env;
beforeEach(() => {
@@ -77,9 +85,11 @@ describe("giteaService", () => {
mockGet = vi.fn();
mockPost = vi.fn();
mockDelete = vi.fn();
vi.mocked(axios.create).mockReturnValue({
get: mockGet,
post: mockPost,
delete: mockDelete,
get: mockGet,
post: mockPost,
} as unknown as ReturnType<typeof axios.create>);
giteaService = new GiteaService();
@@ -306,4 +316,69 @@ describe("giteaService", () => {
{ params: { state: "closed" } },
);
});
it("should get commit status", async() => {
expect.assertions(2);
const mockStatus = {
commit_url: "https://git.nhcarrigan.com/api/v1/repos/owner/repo/commits/abc123",
repository: createMockRepository({ id: 1, name: "test-repo" }),
sha: "abc123",
state: "success",
statuses: [],
total_count: 0,
url: "https://git.nhcarrigan.com/api/v1/repos/owner/repo/commits/abc123/status",
};
mockGet.mockResolvedValueOnce({ data: mockStatus });
const result = await giteaService.getCommitStatus("owner", "repo", "abc123");
expect(result).toStrictEqual(mockStatus);
expect(mockGet).toHaveBeenCalledWith("/repos/owner/repo/commits/abc123/status");
});
it("should merge a pull request successfully", async() => {
expect.assertions(2);
mockPost.mockResolvedValueOnce({ data: {} });
const result = await giteaService.mergePullRequest("owner", "repo", 1);
expect(result).toBe(true);
expect(mockPost).toHaveBeenCalledWith("/repos/owner/repo/pulls/1/merge", {
Do: "merge",
MergeMessageField: "",
MergeTitleField: "",
delete_branch_after_merge: true,
force_merge: false,
head_commit_id: "",
merge_when_checks_succeed: false,
});
});
it("should return false when merge fails", async() => {
expect.assertions(1);
const axiosError = new AxiosError("Merge conflict");
mockPost.mockRejectedValueOnce(axiosError);
const result = await giteaService.mergePullRequest("owner", "repo", 1);
expect(result).toBe(false);
});
it("should delete a branch successfully", async() => {
expect.assertions(2);
mockDelete.mockResolvedValueOnce({ data: {} });
const result = await giteaService.deleteBranch(
"owner",
"repo",
"feature-branch",
);
expect(result).toBe(true);
expect(mockDelete).toHaveBeenCalledWith("/repos/owner/repo/branches/feature-branch");
});
it("should return false when branch deletion fails", async() => {
expect.assertions(1);
const axiosError = new AxiosError("Branch not found");
mockDelete.mockRejectedValueOnce(axiosError);
const result = await giteaService.deleteBranch(
"owner",
"repo",
"nonexistent-branch",
);
expect(result).toBe(false);
});
});