Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/develop_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ jobs:
with:
GITHUB_TOKEN: ${{secrets.TOKEN}}
SLACK_WEBHOOK_URL: ${{secrets.SLACK_WEBHOOK_URL}}
DESTINATION_BRANCH: staging
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ inputs:
SLACK_WEBHOOK_URL:
description: 'Slack webhook'
required: true
DESTINATION_BRANCH:
description: 'destination branch'
required: true
runs:
using: 'node16'
main: './src/develop_actions.js'
Expand Down
38 changes: 24 additions & 14 deletions src/develop_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const core = require("@actions/core");

const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN");
const SLACK_WEBHOOK_URL = core.getInput("SLACK_WEBHOOK_URL");
const DESTINATION_BRANCH = core.getInput("DESTINATION_BRANCH");
const octokit = github.getOctokit(GITHUB_TOKEN);
const { context = {} } = github;

Expand All @@ -19,11 +20,11 @@ const run = async () => {
let commits = "";
try {
const compare_commits = await octokit.request(
`GET /repos/${context.payload?.repository?.full_name}/compare/staging...${branch_name}`,
`GET /repos/${context.payload?.repository?.full_name}/compare/${DESTINATION_BRANCH}...${branch_name}`,
{
owner: context.payload?.repository?.owner?.login,
repo: context.payload?.repository?.name,
base: "staging",
base: DESTINATION_BRANCH,
head: branch_name,
}
);
Expand All @@ -47,10 +48,6 @@ const run = async () => {
? "> " + e.commit.message
: commits + "\n\n" + "> " + e.commit.message;
});

// fetch pr from branch_name to staging to check if it exists
// if pr exists, update
// if not create
} catch (error) {
console.log(error?.message);
}
Expand All @@ -59,12 +56,20 @@ const run = async () => {
try {
let options = {
blocks: [
{
type: "header",
text: {
type: "plain_text",
text: ":sparkles: New notification sent from github actions",
emoji: true,
},
},
{
type: "context",
elements: [
{
type: "mrkdwn",
text: `<:sparkles: PR was created from ${branch_name} to staging>`,
text: `> :sparkles: PR was created from ${branch_name} to ${DESTINATION_BRANCH}`,
},
],
},
Expand All @@ -78,7 +83,7 @@ const run = async () => {
title: branch_name,
body: commits,
head: branch_name,
base: "staging",
base: DESTINATION_BRANCH,
}
);
if (createpr?.data) {
Expand All @@ -100,12 +105,20 @@ const run = async () => {
try {
const options = {
blocks: [
{
type: "header",
text: {
type: "plain_text",
text: ":sparkles: New notification sent from github actions",
emoji: true,
},
},
{
type: "context",
elements: [
{
type: "mrkdwn",
text: `<:sparkles: PR was updated from ${branch_name} to staging>`,
text: `> :sparkles: PR was updated from ${branch_name} to ${DESTINATION_BRANCH}`,
},
],
},
Expand All @@ -117,7 +130,7 @@ const run = async () => {
repo: context.payload?.repository?.name,
state: "open",
head: branch_name,
base: "staging",
base: DESTINATION_BRANCH,
});

if (existing_pr?.data) {
Expand All @@ -129,7 +142,7 @@ const run = async () => {
title: branch_name,
body: commits,
head: branch_name,
base: "staging",
base: DESTINATION_BRANCH,
});
if (update_pr.data) {
// send slack notification
Expand All @@ -150,6 +163,3 @@ const run = async () => {
};

run();

// $GITHUB_REF would look like (refs/pull/33/merge), $GITHUB_HEAD_REF would just store the source branch name while $GITHUB_BASE_REF would represent RP destination branch. Maybe you can update your answer to fallback to $GITHUB_HEAD_REF
// ${GITHUB_REF##*/}