Skip to content

Commit

Permalink
Edit workflow to get title from env file
Browse files Browse the repository at this point in the history
  • Loading branch information
zaelgohary committed Aug 7, 2024
1 parent 0ec163c commit 37fb66d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
title: Someone just pushed
title: Someone just pushed {{ env.ISSUE_TITLE }}
labels: bug
---
57 changes: 14 additions & 43 deletions .github/workflows/issue_creation.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Create Issue if Not Exists

# .github/workflows/issue-on-push.yml
on:
push:
branches:
Expand All @@ -10,50 +11,20 @@ permissions:
issues: write

jobs:
create_issue:
stuff:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v3

- name: Generate Dynamic Issue Title and Content
id: generate_issue
- name: 'Create env file'
run: |
ISSUE_TITLE="Issue from push: $(date +'%Y-%m-%d %H:%M:%S')"
ISSUE_BODY="This issue was automatically created based on a push to the development_issue_creation branch.\n\nTimestamp: $(date +'%Y-%m-%d %H:%M:%S')"
echo "::set-output name=title::$ISSUE_TITLE"
echo "::set-output name=body::$ISSUE_BODY"
- name: Check for existing issues
id: check_issue
uses: actions/github-script@v6
touch .env
echo ISSUE_TITLE="Title from Github workflow" >> .env
cat .env
- uses: actions/checkout@v3
- uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const title = "${{ steps.generate_issue.outputs.title }}";
const { data: issues } = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
});
const issueExists = issues.some(issue => issue.title === title);
return { issueExists: issueExists };
- name: Create a new issue if not exists
if: steps.check_issue.outputs.issueExists == 'false'
uses: actions/github-script@v6
with:
script: |
const title = "${{ steps.generate_issue.outputs.title }}";
const body = "${{ steps.generate_issue.outputs.body }}";
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body
});
- name: Issue already exists
if: steps.check_issue.outputs.issueExists == 'true'
run: echo "Issue with title '${{ steps.generate_issue.outputs.title }}' already exists."
update_existing: false
search_existing: open
filename: .github/issue_template.md

0 comments on commit 37fb66d

Please sign in to comment.