Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
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
32 changes: 23 additions & 9 deletions .github/actions/conventional-pr/src/conventional-pr.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import * as core from '@actions/core';
import * as github from '@actions/github';

import { validateTitle, validateBody } from './utils';
import {
validateTitle,
validateBody,
validateBaseBranch,
PullRequestInfo,
isRelease,
} from './utils';

const OWNER = github.context.repo.owner;
const REPO = github.context.repo.repo;
Expand All @@ -22,6 +28,7 @@ const prQuery = `
pullRequest(number: $prNumber) {
title
body
baseRefName
}
}
}
Expand All @@ -43,22 +50,29 @@ async function run() {
repo: REPO,
prNumber,
});
const pr = repository.pullRequest;
const pr = repository?.pullRequest as PullRequestInfo;

if (!pr) {
core.setFailed('Not in a Pull Request context.');
return;
}

const titleErrors = validateTitle(pr.title);
const bodyErrors = validateBody(pr.body);
if (!isRelease(pr)) {
const titleErrors = validateTitle(pr.title);
const bodyErrors = validateBody(pr.body);
const branchErrors = validateBaseBranch(pr.title, pr.baseRefName);

if (titleErrors.length) {
core.setFailed(titleErrors.join('\n'));
}
if (titleErrors.length) {
core.setFailed(titleErrors.join('\n'));
}

if (bodyErrors.length) {
core.setFailed(bodyErrors.join('\n'));
if (bodyErrors.length) {
core.setFailed(bodyErrors.join('\n'));
}

if (branchErrors.length) {
core.setFailed(branchErrors.join('\n'));
}
}
} catch (err) {
core.error(err);
Expand Down
26 changes: 26 additions & 0 deletions .github/actions/conventional-pr/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import * as core from '@actions/core';

export interface PullRequestInfo {
title: string;
body: string;
baseRefName: string;
}
type ValidationResult = string[];

const validTypes = [
Expand Down Expand Up @@ -52,3 +57,24 @@ export function validateBody(body: string): ValidationResult {

return errors;
}

export function isRelease(pr: PullRequestInfo) {
return pr.title.startsWith('release: ') && pr.baseRefName === 'stable';
}

export function validateBaseBranch(
title: string,
baseBranch: string
): ValidationResult {
let errors: ValidationResult = [];

if (title.startsWith('release: ') && baseBranch !== 'stable') {
errors.push("[Release] Release pull request must target 'stable' branch.");
} else if (baseBranch === 'stable') {
errors.push(
"[Branch] Pull requests cannot target 'stable' branch. Perhaps you meant to create a release or are targeting the wrong branch."
);
}

return errors;
}