Goal

  • Understand the GitHub workflow with pull requests

Specification of app

  • Create a simple command-line ToDo application in Go.
  • The application should allow users to add, list, complete, and delete tasks.
  • Tasks should be stored in a JSON file named todo.json.

Add a task

  • Command: add "task title"
  • Adds a new task with the given title to todo.json.
go run . add "Buy milk"

List tasks

  • Command: list
  • Lists all tasks with their IDs, titles, and completion status.
go run . list
1: Buy milk [ ] # [ ] means not completed
2: Walk the dog [x] # [x] means completed
3: Read a book [ ] # [ ] means not completed

Complete a task

  • Command: complete <task_id>
  • Marks the task with the given ID as completed in todo.json.
  • If the task does not exist, it should print an error message.
go run . complete 1

Delete a task

  • Command: delete <task_id>
  • Deletes the task with the given ID from todo.json.
  • If the task does not exist, it should print an error message.
go run . delete 1

Instructions

  • Divide into two smaller two groups (2–3 people each).
  • Both groups will work on the same repository, editing todo.go.
Group A Group B
AddTask(title string) CompleteTask(id int)
ListTasks() DeleteTask(id int)
  • Each group will:
    • Create a feature branch for their tasks
    • Implement their assigned functions in todo.go
    • Use mob programming (one person types, others guide)
    • Push changes and create a pull request (PR) for review and merging
repo/
├── main.go  # do not edit this file
└── todo.go  # two groups will edit this file

Branch: feature/add-list
  - implements AddTask()
  - implements ListTasks()

Branch: feature/complete-delete
  - implements CompleteTask()
  - implements DeleteTask()

Steps

  1. Fork the repository: Only one member of each group needs to fork the repository to their own GitHub account.
    • Press the “Fork” button on the top right of the repository page on GitHub.
    • Share the forked repository URL with the rest of the group.
    • The URL will look like: https://github.com/yourusername/todo-app
  2. Add team members as collaborators: The member who forked the repository should add the other group members as collaborators.
    • Go to the repository settings on GitHub.
    • Click on “Manage access” and invite your team members by their GitHub usernames or email addresses.
  3. Clone the repository: One member of the group should clone the forked repository.
    • Use the following command:
      git clone https://github.com/yourusername/todo-app.git
      cd todo-app
      
  4. Create a new branch: Each group creates a new branch for their assigned feature implementation.
    • Example:
      git checkout -b feature/add-list
      

      or

      git checkout -b feature/complete-delete
      
  5. Implement the feature: Each group implements their assigned functions in todo.go.
    • Group A: AddTask() and ListTasks()
    • Group B: CompleteTask() and DeleteTask()
    • Follow the provided function signatures (which initially contain panic(“unimplemented”)).
  6. Commit the changes: After completing implementation and testing locally, commit the changes.
    git add todo.go
    git commit -m "Implement AddTask and ListTasks"
    
  7. Push the changes: Push your feature branch to the remote repository on GitHub.
    git push origin feature/add-list
    
  8. Create a pull request: Open a pull request to merge your branch into the main branch.
    • Go to the GitHub repository page.
    • Click on the “Pull requests” tab.
    • Click “New pull request”
    • Select your feature branch to merge into main
    • Write a title and description, then click “Create pull request”
  9. Review and merge the pull request: The other group should review the pull request.
    • If approved, click “Merge pull request”
    • Confirm the merge
  10. Pull the updated main branch: After merging, the other group should update their local main branch:
    git checkout main
    git pull origin main
    
  11. Repeat for the other group: The second group now repeats steps 3–8 for their assigned features.

Submit the Exercise

  • After both groups have completed their tasks and merged their pull requests, please submit the exercise using the form below. In the Exercise title field, select Practice for GitHub Workflow and provide the link to your forked repository

Submit your exercise here