Skip to content

Commit

Permalink
feat: added action
Browse files Browse the repository at this point in the history
  • Loading branch information
Gyanthakur committed Oct 1, 2024
1 parent fd9ad60 commit 27c6bd8
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 14 deletions.
34 changes: 20 additions & 14 deletions .github/workflows/greetings.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
name: Greetings # Required root key
# File location: .github/workflows/greetings.yml
name: Greetings Workflow with Auto-Assign

on: # Required root key
on: # Trigger events
push:
branches: [main]
branches: [main]
issues:
types: [opened]
types: [opened] # Trigger on issue opened
pull_request_target:
types: [opened]
types: [opened] # Trigger on pull request opened

jobs:
greet-and-assign:
runs-on: ubuntu-latest # The environment

jobs: # Required root key
welcome:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: EddieHubCommunity/gh-action-community@main
- name: Checkout repository content
uses: actions/checkout@v3 # Checks out the repository

- name: Run greeting and assign action
uses: ./ # This points to the root directory where action.yml resides
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: 'Welcome, @{{ github.actor }}! Thanks for raising the issue!'
pr-message: 'Great job, @{{ github.actor }}! Thanks for creating the pull request!'
footer: 'Soon the maintainers/owner will review it and provide you with feedback/suggestions. Make sure to star this awesome repository.'
github-token: ${{ secrets.GITHUB_TOKEN }} # GitHub authentication
issue-message: 'Welcome, @{{ github.actor }}! Thanks for opening this issue!'
pr-message: 'Great job, @{{ github.actor }}! Thanks for the pull request!'
footer: 'The maintainers will review your request soon. Stay tuned!'
assign-user: 'username-to-assign' # You can replace this with any username or GitHub handle
29 changes: 29 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# File location: action.yml
name: 'Greeting and Auto-Assign Action'
description: 'This action greets users and assigns a team member when an issue or pull request is opened.'
author: 'Gyan Pratap Singh'

inputs:
github-token:
description: 'GitHub token for authentication.'
required: true
issue-message:
description: 'The message to post when an issue is opened.'
required: true
pr-message:
description: 'The message to post when a pull request is opened.'
required: true
footer:
description: 'Optional footer to include in the greeting.'
required: false
assign-user:
description: 'The GitHub username to assign to the issue or pull request.'
required: true

runs:
using: 'node16'
main: 'index.js' # Points to the main script for logic

branding:
icon: 'wave'
color: 'green'
52 changes: 52 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// File location: index.js
const core = require('@actions/core');
const github = require('@actions/github');

async function run() {
try {
const githubToken = core.getInput('github-token');
const issueMessage = core.getInput('issue-message');
const prMessage = core.getInput('pr-message');
const footer = core.getInput('footer') || '';
const assignUser = core.getInput('assign-user'); // New input for assigning user

const octokit = github.getOctokit(githubToken);
const context = github.context;

if (context.payload.issue) {
// This is an issue
const issueComment = `${issueMessage}\n\n${footer}`;
await octokit.issues.createComment({
...context.repo,
issue_number: context.payload.issue.number,
body: issueComment,
});

// Auto-assign user to issue
await octokit.issues.addAssignees({
...context.repo,
issue_number: context.payload.issue.number,
assignees: [assignUser],
});
} else if (context.payload.pull_request) {
// This is a pull request
const prComment = `${prMessage}\n\n${footer}`;
await octokit.issues.createComment({
...context.repo,
issue_number: context.payload.pull_request.number,
body: prComment,
});

// Auto-assign user to PR
await octokit.issues.addAssignees({
...context.repo,
issue_number: context.payload.pull_request.number,
assignees: [assignUser],
});
}
} catch (error) {
core.setFailed(error.message);
}
}

run();

0 comments on commit 27c6bd8

Please sign in to comment.