This project automates the creation of GitHub issues based on specified frequency and project configurations set through environment variables.
- Reads project configurations from environment variables.
- Creates GitHub issues based on the specified frequency (Daily, Weekly, Monthly, Quarterly).
- Checks the last issue created with the same title to determine if a new issue needs to be created.
- Can be conveniently integrated and used with Jenkins for automation.
The script relies on the following environment variables:
GITHUB_TOKEN
: Your GitHub personal access token.ISSUE_TITLE
: The title of the issue to be created.ISSUE_BODY
: The body content of the issue to be created.PROJECT_*
: Environment variables for each project, formatted asPROJECT_<NAME>="FREQUENCY|USER|REPO"
, where:<NAME>
is the name of the project.FREQUENCY
is one ofDaily
,Weekly
,Monthly
, orQuarterly
.USER
is the GitHub username.REPO
is the GitHub repository name.
-
Clone the repository:
git clone https://github.com/yourusername/github-issue-creator.git cd github-issue-creator
-
Set up your environment variables. You can create a
.env
file in the project directory:GITHUB_TOKEN=your_github_token ISSUE_TITLE=Your Issue Title ISSUE_BODY=Your issue body content PROJECT_EXAMPLE="Daily|username|repository"
-
Run the script:
php recurring-issue-generator.php
This script can be conveniently used within Jenkins for automation. Follow these steps to integrate it into a Jenkins pipeline:
-
Install the EnvInject Plugin: This plugin allows you to inject environment variables into the build process.
-
Create a Jenkins Job:
- Configure a new Jenkins job (Freestyle Project or Pipeline).
- In the Build Environment section, check the Inject environment variables to the build process option.
- Provide the path to your
.env
file or specify the environment variables directly.
-
Add a Build Step:
- Add an Execute shell build step.
- In the shell command section, enter the following commands:
# Navigate to the project directory cd /path/to/github-issue-creator # Run the PHP script php script.php
-
Save and Build: Save the job configuration and run the build. The script will execute and create GitHub issues as configured.
- getProjectConfigs(): Retrieves the project configurations from environment variables.
- createGitHubIssue($repo, $user, $githubToken, $title, $body): Creates a GitHub issue in the specified repository.
- checkLastIssue($repo, $frequency, $githubToken, $title): Checks the last issue created with the same title and determines if a new issue needs to be created based on the specified frequency.
Given the following environment variables:
GITHUB_TOKEN=your_github_token
ISSUE_TITLE=Test Issue
ISSUE_BODY=This is a test issue.
PROJECT_PROJECT1="Daily|username1|repo1"
PROJECT_PROJECT2="Weekly|username2|repo2"
The script will attempt to create a GitHub issue with the title "Test Issue" and body "This is a test issue." in the repositories repo1 (owned by username1) daily and repo2 (owned by username2) weekly, based on the last issue created with the same title.