Skip to content

Commit

Permalink
Merge pull request #1 from opencepk/feat/githubaction-custom
Browse files Browse the repository at this point in the history
custom git actions
  • Loading branch information
hminaee-tc authored Jul 14, 2024
2 parents e5c4b98 + 84ca551 commit 8dbebff
Show file tree
Hide file tree
Showing 9 changed files with 679 additions and 0 deletions.
98 changes: 98 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,99 @@

# Custom gitignores

.DS_Store
logs/


# Covers VSCode
**/node_modules
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
9 changes: 9 additions & 0 deletions check-pr-blockage/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: 'Check PR for Blockage'
description: 'Fail if the first PR comment contains a blockage notice'
runs:
using: 'node20'
main: 'index.js'
inputs:
github-token:
description: 'GitHub token for accessing the PR comments'
required: true
57 changes: 57 additions & 0 deletions check-pr-blockage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const core = require('@actions/core');
const github = require('@actions/github');

async function run() {
try {
const token = core.getInput('github-token', { required: true });
const octokit = github.getOctokit(token);

const { owner, repo, number: currentPRNumber } = github.context.issue;

// Fetch all comments of the PR
const { data: comments } = await octokit.rest.issues.listComments({
owner,
repo,
issue_number: currentPRNumber,
});

if (comments.length === 0) {
core.setFailed('No comments found in the PR.');
return;
}

const blockedByRegex = /blocked by #(\d+)/i;
let isBlocked = false;

for (const comment of comments) {
const match = blockedByRegex.exec(comment.body);
if (match) {
const blockingPRNumber = match[1];

// Check if the blocking PR is merged
const { data: pr } = await octokit.rest.pulls.get({
owner,
repo,
pull_number: blockingPRNumber,
});

if (!(pr.merged || pr.state === 'closed')) {
core.setFailed(`PR is blocked by an unmerged PR #${blockingPRNumber}.`);
isBlocked = true;
break; // Exit the loop as we found a blocker
} else {
core.info(`Found a blocking comment: PR is blocked by #${blockingPRNumber} but it is closed. So it is not blocking.`);
}
}
}

if (!isBlocked) {
core.info('PR is not blocked by any PR mentioned in comments.');
}

} catch (error) {
core.setFailed(`Action failed with error ${error}`);
}
}

run();
215 changes: 215 additions & 0 deletions check-pr-blockage/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions check-pr-blockage/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "check-pr-blockage",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"@actions/core": "^1.6.0",
"@actions/github": "^5.0.0"
}
}
Loading

0 comments on commit 8dbebff

Please sign in to comment.