Skip to content

Baseline lab automation for lab #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
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
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/build-lab-issue-basics-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Build Lab-Issue Basics template
about: 'This template was created to save typing in the '
title: Investigate Issue Basics
labels: ''

---

# Issue Basics

This task describes the lab steps required to complete the "Issue Basics" tasks. As a template item, this description was filled out for you in advance (to save typing). Generally, you will use templates to get started with a standard format and content but add additional information. In this case, the issue is complete as-is...

To complete this task you will:
- [x] Use an issue template (done)
- [x] Review markdown used to format content in GitHub. You're looking at it now, but if you aren't already familiar with markdown you can refer to [this link](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github). If you've already saved it and want to review the source markdown you can edit the description to see the unformatted text.
- [ ] Apply Labels
- [ ] Apply Milestones
- [ ] Query Issues
- [ ] Verify automation triggered by issues
23 changes: 23 additions & 0 deletions .github/scripts/issue-seeds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{ "id": 0, "title": "Learning GitHub Issues Batch" },
{ "id": 1, "title": "Exercise Project Fundamentals", "type": "Feature"},
{ "title": "Create a new project", "type": "Task", "parent": 1},
{ "title": "Add all of the remaining issues", "type": "Task", "parent": 1},
{ "id": 2, "title": "Customize Status and Fields", "type": "Feature", "labels": "enhancement" },
{ "title": "Add priority field", "type": "Task", "parent": 2},
{ "title": "Add start and end date fields", "type": "Task", "parent": 2},
{ "title": "Add 'Paused' status", "type": "Task", "parent": 2},
{ "id": 3, "title": "Filter Project Data", "type": "Feature", "labels": "enhancement" },
{ "title": "Rename view 'Feature Planning'", "type": "Task", "parent": 3},
{ "title": "Add Feature/Bug filter", "type": "Task", "parent": 3},
{ "id": 4, "title": "Add 'Release Planning' view", "type": "Feature" },
{ "title": "Populate date fields", "type": "Task", "parent": 4},
{ "title": "Duplicate 'Feature Planning'", "type": "Task", "parent": 4},
{ "title": "Rename to 'Release Roadmap' and set 'Roadmap' view", "type": "Task", "parent": 4},
{ "title": "Scale to quarter and sort by End date", "type": "Task", "parent": 4},
{ "title": "Refine release dates", "type": "Task", "parent": 4},
{ "id": 5, "title": "Add Board view for tasks", "type": "Feature" },
{ "title": "Add a view named 'Task Board' filtered on Tasks and untyped issues", "type": "Task", "parent": 5},
{ "title": "Add a Parent Issue slice, Group by Assignees, and add the Labels field", "type": "Task", "parent": 5},
{ "title": "Fix the typo in the README file", "type": "Bug", "body": "The 'Abstract' header on line 3 is misspelled." }
]
177 changes: 177 additions & 0 deletions .github/scripts/prepare-lab-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#!/bin/bash
# Bash script to set up GitHub lab environment dedicated to Issues and Projects.

# If "--delete" is passed as an argument, delete all issues in the repository
if [[ "$1" == "--delete" || "$1" == "--seed-all" ]]; then
echo "Deleting all issues..."
gh issue list --limit 1000 | awk '{print $1}' | xargs -I {} gh issue delete {} --yes
fi

# If "--seed" is passed as an argument, automatically create issues that are meant to be manually created
if [[ "$1" == "--seed-all" ]]; then
gh issue create \
--title "Investigate Issue Basics" \
--body "
# Issue Basics

This task describes the lab steps required to complete the Issue Basics tasks. As a template item, this description was filled out for you in advance (to save typing). Generally, you will use templates to get started with a standard format and content but add additional information. In this case, the issue is complete as-is...

To complete this task you will:
- [x] Use an issue template (done)
- [x] Review markdown used to format content in GitHub. You're looking at it now, but if you aren't already familiar with markdown you can refer to [this link](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github). If you've already saved it and want to review the source markdown you can edit the description to see the unformatted text.
- [ ] Apply Labels
- [ ] Apply Milestones
- [ ] Query Issues
- [ ] Verify automation triggered by issues" \
--assignee "@me"
fi

# Function to load issue seeds from a JSON file
load_issue_seeds() {
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "Error: jq is not installed. Please install it with: sudo apt-get install jq" >&2
return 1
fi

# Check if file exists
local file_path="issue-seeds.json"
if [[ ! -f "$file_path" ]]; then
echo "Error: $file_path not found in current directory." >&2
return 1
fi

# Read the JSON file and return the content
local json_content
json_content=$(jq '.' "$file_path")

# Check if the JSON is valid
if [[ $? -ne 0 ]]; then
echo "Error: Failed to parse JSON file." >&2
return 1
fi

# Echo the JSON content
echo "$json_content"

}

# Function to create a GitHub issue from a JSON issue object
create_issue_from_json() {
local issue_json="$1"

# Extract issue properties with proper error handling
local id=$(echo "$issue_json" | jq -r '.id // empty')
local title=$(echo "$issue_json" | jq -r '.title // empty')
local body=$(echo "$issue_json" | jq -r '.body // empty')
# local labels=$(echo "$issue_json" | jq -r '.labels // [] | join(",")')
local labels=$(echo "$issue_json" | jq -r '.labels // empty')
local milestone=$(echo "$issue_json" | jq -r '.milestone // empty')
local parent=$(echo "$issue_json" | jq -r '.parent // empty')

# Validate required fields
if [[ -z "$title" ]]; then
echo "Error: Issue title is required." >&2
return 1
fi

echo "Creating issue: $title"

# Build the gh issue create command
local cmd="gh issue create --title \"$title\" --body \"$body\""

# Add labels if provided
if [[ -n "$labels" && "$labels" != "" ]]; then
cmd="$cmd --label \"$labels\""
fi

# Add milestone if provided
if [[ -n "$milestone" && "$milestone" != "null" ]]; then
cmd="$cmd --milestone \"$milestone\""
fi

# Execute the command to create the issue
issue_url=$(eval "$cmd")

# Check if issue was created successfully
if [[ $? -eq 0 ]]; then
echo "Successfully created issue: $issue_url"

# Parse the issue number from the URL
issue_number=$(echo "$issue_url" | grep -oE '[0-9]+$')

# Modify the URL to create the related API URL
api_url=$(echo "/repos/$issue_url" | sed 's/https:\/\/github.com\///')

# Set the issue Type based on the JSON "type" field
issue_type=$(echo "$issue_json" | jq -r '.type // empty')

# Use the GitHub CLI to call the api_url and apply the issue_type
echo "Setting issue type to: $issue_type"
gh api -X PATCH "$api_url" -f type="$issue_type"

# Capture the parent issue number if provided
if [[ -n "$id" && "$id" != "null" ]]; then
echo "Capturing issue ID[$id] = $issue_number"
parent_issue_numbers[$id]=$issue_number
fi

# If a parent issue is specified, create the relationship
if [[ -n "$parent" && "$parent" != "null" ]]; then
echo "Attempting to add relationship with parent issue: $parent"

# Look up this issue's node_id
child_id=$(gh api -X GET "$api_url" | jq -r '.id // empty')

# Check the parent issue number array
if [[ "${parent_issue_numbers[$parent]}" ]]; then

# create a version of the API URL for the parent issue
parent_id=${parent_issue_numbers[$parent]}
parent_api_url=$(echo "$api_url" | sed -E "s|/([0-9]+)$|/$parent_id/sub_issues|")

# Add the sub-issue relationship via the GitHub API
echo "Adding sub-issue relationship from $parent_id to $issue_number"
gh api $parent_api_url -X POST -F sub_issue_id=$child_id
fi
fi

return 0
else
echo "Failed to create issue: $title" >&2
return 1
fi
}

# ------------------------------------------------------------
# Seed automation issues required for the lab
# ------------------------------------------------------------
if [[ "$1" == "" || "$1" == "--seed-all" ]]; then

# Call the function and store the result in a variable
echo "Reading seed issues for the lab..."
issue_seeds_json=$(load_issue_seeds)

if [[ $? -eq 0 ]]; then
echo "Successfully loaded $(echo "$issue_seeds_json" | jq 'length') issue seeds."

# Initialize an array for parent issue numbers
declare -a parent_issue_numbers=()

# Loop through each issue in the JSON array
for i in $(seq 0 $(( $(echo "$issue_seeds_json" | jq 'length') - 1 ))); do
# Extract the issue object
issue=$(echo "$issue_seeds_json" | jq ".[$i]")

# Create issue from the JSON object
create_issue_from_json "$issue"

# Optional: Add a small delay between issue creation to avoid rate limits
# sleep 1
done
else
echo "Failed to load issue seeds JSON"
exit 1
fi
fi

1 change: 1 addition & 0 deletions .github/workflows/.run-once
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The purpose of this file is to cause a trigger of a workflow when this repo is first created from a template. If you modify this file later and commit the code, it will re-run that workflow, which may have unintended consequences.
27 changes: 27 additions & 0 deletions .github/workflows/issue-ping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Issue automation lab sample

on:
issue_comment:
types: [created]

permissions:
issues: write
contents: read

jobs:
respond_to_ping:
runs-on: ubuntu-latest
if: contains(github.event.comment.body, 'ping')

steps:
- name: Respond with pong
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'pong'
});
32 changes: 32 additions & 0 deletions .github/workflows/lab-issue-automation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
# Manual run with parameter for what to do
workflow_dispatch:
inputs:
command:
required: false
type: choice
options:
- --delete
- --seed-all
# Automatic run when this is first created from a template
push:
branches:
- main
paths:
- .github/workflows/.run-once

permissions:
issues: write
contents: read

jobs:
seed_issues:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- run: ./prepare-lab-env.sh $OPTION
shell: bash
working-directory: .github/scripts
env:
OPTION: ${{ inputs.command }}
GH_TOKEN: ${{ github.token }}
74 changes: 74 additions & 0 deletions CODE_OF_CONTENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Contributing

[fork]: https://github.com/github/startups-content/fork
[pr]: https://github.com/github/startups-content/compare
[code-of-conduct]: CODE_OF_CONDUCT.md

Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.

Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE.md).

Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.

## Prerequisites for running and testing code

There are no external tools required to run and test this code. It only contains one Bash script and Actions YAML. The real value of this repo is the markdown documentation which doesn't require additional tools.

## Submitting a pull request

1. [Fork][fork] and clone the repository
2. Make your change
3. Push to your fork and [submit a pull request][pr]
4. Pat your self on the back and wait for your pull request to be reviewed and merged.

- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).

## Resources

- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
- [GitHub Help](https://help.github.com)
Loading