-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue.sh
executable file
·56 lines (43 loc) · 1.71 KB
/
issue.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
###############################################################################
# Title: Create GitHub Issue
#
# Description: This script creates a new issue in a GitHub repository. It
# automatically applies the 'bug' label if the '-f' argument is
# not provided, or the 'enhancement' label if the '-f' argument
# is present. It also creates a new branch for the issue, links
# the branch to the issue, assigns the issue to the user, and
# switches to the newly created branch.
#
# Author: Amjed Ali (@amjed-ali-k)
###############################################################################
# Set the repository owner and name
OWNER="UNQ-Technologies"
REPO="trafitizer-landing"
# Set the labels based on the '-f' argument
if [[ "$*" == *"-f"* ]]; then
LABELS="enhancement"
else
LABELS="bug"
fi
# Extract the title from the arguments
TITLE=$(echo "$*" | sed -e 's/.*-t \(.*\)/\1/')
# Generate a random issue ID
ISSUE_ID=$(openssl rand -hex 4)
# Get the current date and time
CURRENT_TIME=$(date +'%Y-%m-%d %H:%M:%S')
# Get the author's name and email
AUTHOR_NAME=$(git config --get user.name)
AUTHOR_EMAIL=$(git config --get user.email)
# Create the issue body
ISSUE_BODY=$(cat <<-END
**Created Time:** $CURRENT_TIME
**Author:** $AUTHOR_NAME ($AUTHOR_EMAIL)
**Random ID:** $ISSUE_ID
END
)
# Create a new issue
ISSUE=$(gh issue create --repo "$OWNER/$REPO" --title "$TITLE" --body "$ISSUE_BODY" --label "$LABELS" --assignee "@me")
# Create a new branch for the issue
gh issue develop $ISSUE --repo "$OWNER/$REPO" --base "$(git rev-parse --abbrev-ref HEAD)" -c
echo "New issue #$ISSUE created and assigned to you. Branch created and linked to the issue."