- Add Increment:
A-MoreOOP
- Add Increments as PRs:
Level-8
,Level-9
,A-JavaDoc
- Set up a product website
- Submit the final version Fri, Oct 2nd 2359
1 Add Increment: A-MoreOOP
- As in the previous week, commit, tag, and push, as you do the following increments in the
master
branch (no need to use separate branches).
A-MoreOOP
: Use More OOP Refactor the code to extract out closely related code as classes.
- Minimal: Extract the following classes:
Ui
: deals with interactions with the userStorage
: deals with loading tasks from the file and saving tasks in the fileParser
: deals with making sense of the user commandTaskList
: contains the task list e.g., it has operations to add/delete tasks in the list
For example, the code of the main class could look like this:
public class Duke {
private Storage storage;
private TaskList tasks;
private Ui ui;
public Duke(String filePath) {
ui = new Ui();
storage = new Storage(filePath);
try {
tasks = new TaskList(storage.load());
} catch (DukeException e) {
ui.showLoadingError();
tasks = new TaskList();
}
}
public void run() {
//...
}
public static void main(String[] args) {
new Duke("data/tasks.txt").run();
}
}
- Stretch Goal: Consider extracting more classes. e.g.,
*Command
classes (i.e.,AddCommand
,DeleteCommand
,ExitCommand
etc.) that inherits from an abstractCommand
class, so that you can write the main logic of the App as follows:
You can get some inspiration from how the code of the addressbook-level2 is organized.public void run() {
ui.showWelcome();
boolean isExit = false;
while (!isExit) {
try {
String fullCommand = ui.readCommand();
ui.showLine(); // show the divider line ("_______")
Command c = Parser.parse(fullCommand);
c.execute(tasks, ui, storage);
isExit = c.isExit();
} catch (DukeException e) {
ui.showError(e.getMessage());
} finally {
ui.showLine();
}
}
}
2 Add Increments as PRs: Level-8
, Level-9
, A-JavaDoc
- Note how to merge PRs:
Textbook Git & GitHub → Merging PRs
Let's look at the steps involved in merging a PR, assuming the PR has been reviewed, refined, and approved for merging already.
Preparation: If you would like to try merging a PR yourself, you can create a dummy PR in the following manner.
- Fork any repo (e.g., samplerepo-pr-practice).
- Clone in to your computer.
- Create a new branch e.g., (
feature1
) and add some commits to it. - Push the new branch to the fork.
- Create a PR from that branch to the
master
branch in your fork. Yes, it is possible to create a PR within the same repo.
1. Locate the PR to be merged in your repo's GitHub page.
2. Click on the Conversation tab and scroll to the bottom. You'll see a panel containing the PR status summary.
3. If the PR is not merge-able in the current state, the Merge pull request will not be green. Here are the possible reasons and remedies:
- Problem: The PR code is out-of-date, indicated by the message This branch is out-of-date with the base branch. That means the repo's
master
branch has been updated since the PR code was last updated.- If the PR author has allowed you to update the PR and you have sufficient permissions, GitHub will allow you to update the PR simply by clicking the Update branch on the right side of the 'out-of-date' error message. If that option is not available, post a message in the PR requesting the PR author to update the PR.
- Problem: There are merge conflicts, indicated by the message This branch has conflicts that must be resolved. That means the repo's
master
branch has been updated since the PR code was last updated, in a way that the PR code conflicts with the currentmaster
branch. Those conflicts must be resolved before the PR can be merged.- If the conflicts are simple, GitHub might allow you to resolve them using the Web interface.
- If that option is not available, post a message in the PR requesting the PR author to update the PR.
Tools → Git and GitHub →
Merge conflicts happen when you try to combine two incompatible versions (e.g., merging a branch to another but each branch changed the same part of the code in a different way).
Here are the steps to simulate a merge conflict and use it to learn how to resolve merge conflicts.
0. Create an empty repo or clone an existing repo, to be used for this activity.
1. Start a branch named fix1
in the repo. Create a commit that adds a line with some text to one of the files.
2. Switch back to master
branch. Create a commit with a conflicting change i.e. it adds a line with some different text in the exact location the previous line was added.
3. Try to merge the fix1
branch onto the master
branch. Git will pause mid-way during the merge and report a merge conflict. If you open the conflicted file, you will see something like this:
COLORS
------
blue
<<<<<< HEAD
black
=======
green
>>>>>> fix1
red
white
4. Observe how the conflicted part is marked between a line starting with <<<<<<
and a line starting with >>>>>>
, separated by another line starting with =======
.
Highlighted below is the conflicting part that is coming from the master
branch:
blue
<<<<<< HEAD
black
=======
green
>>>>>> fix1
red
This is the conflicting part that is coming from the fix1
branch:
blue
<<<<<< HEAD
black
=======
green
>>>>>> fix1
red
5. Resolve the conflict by editing the file. Let us assume you want to keep both lines in the merged version. You can modify the file to be like this:
COLORS
------
blue
black
green
red
white
6. Stage the changes, and commit.
3. Merge the PR by clicking on the Merge pull request button, followed by the Confirm merge
button. You should see a Pull request successfully merged and closed
message after the PR is merged.
- You can choose between three merging options by clicking on the down-arrow in the Merge pull request button. If you are new to Git and GitHub, the
Create merge commit
options are recommended.
Next, sync your local repos (and forks). Merging a PR simply merges the code in the upstream remote repository in which it was merged. The PR author (and other members of the repo) needs to pull the merged code from the upstream repo to their local repos and push the new code to their respective forks to sync the fork with the upstream repo.
- Practice using parallel git branches and PRs, as explained below:
- First, do each increment as a parallel branch (follow the branch naming convention you followed earlier
branch-Level-8
etc.), but do not merge any. - Then, push each branch to your fork, and create a PR within your fork (i.e., from the increment branch to the
master
branch). Be careful not to create a PR to the upstream repo. If you did create such a PR by mistake, no worries, just close it yourself.
Textbook Git & GitHub → Creating PRs
Suppose you want to propose some changes to a GitHub repo (e.g., samplerepo-pr-practice) as a pull request (PR). Here is a scenario you can try in order to learn how to create PRs:
A pull request (PR for short) is a mechanism for contributing code to a remote repo, i.e., "I'm requesting you to pull my proposed changes to your repo". For this to work, the two repos must have a shared history. The most common case is sending PRs from a fork to its upstream repo is a repo you forked fromupstream repo.
1. Fork the repo onto your GitHub account.
2. Clone it onto your computer.
3. Commit your changes e.g., add a new file with some contents and commit it.
- Option A - Commit changes to the
master
branch - Option B - Commit to a new branch e.g., create a branch named
add-intro
(remember to switch to themaster
branch before creating a new branch) and add your commit to it.
4. Push the branch you updated (i.e., master
branch or the new branch) to your fork, as explained here.
Pushing a branch to a remote repo
Here's how to push a branch to a remote repo:
Here's how to push a branch named add-intro
to your own fork of a repo named samplerepo-pr-practice
:
Normally: git push {remote repository} {branch}
. Examples:
git push origin master
pushes themaster
branch to the repo namedorigin
(i.e., the repo you cloned from)git push upstream-repo add-intro
pushes theadd-intro
branch to the repo namedupstream-repo
If pushing a branch you created locally to the remote for the first time, add the -u
flag to get the local branch to track the new upstream branch:
e.g., git push -u origin add-intro
See git-scm.com/docs/git-push for details of the push
command.
5. Initiate the PR creation:
-
Go to your fork.
-
Click on the Pull requests tab followed by the New pull request button. This will bring you to the 'Comparing changes' page.
-
Set the appropriate target repo and the branch that should receive your PR, using the
base repository
andbase
dropdowns. e.g.,
base repository: se-edu/samplerepo-pr-practice base: masterNormally, the default value shown in the dropdown is what you want but in case your fork has e.g., the repo you forked from is also a fork of a another repo, which means both of those are considered upstream repos of your forkmultiple upstream repos, the default may not be what you want.
-
Indicate which repo:branch contains your proposed code, using the
head repository
andcompare
dropdowns. e.g.,
head repository: myrepo/samplerepo-pr-practice compare: master
6. Verify the proposed code: Verify that the diff view in the page shows the exact change you intend to propose. If it doesn't, commit the new code and push to the branchupdate the branch as necessary.
7. Submit the PR:
-
Click the Create pull request button.
-
Fill in the PR name and description e.g.,
Name:Add an introduction to the README.md
Description:Add some paragraph to the README.md to explain ...
Also add a heading ... -
If you want to indicate that the PR you are about to create is 'still work in progress, not yet ready', click on the dropdown arrow in the Create pull request button and choose
Create draft pull request
option. -
Click the Create pull request button to create the PR.
-
Go to the receiving repo to verify that your PR appears there in the
Pull requests
tab.
The next step of the PR life cycle is the PR review. The members of the repo that received your PR can now review your proposed changes.
- If they like the changes, they can merge the changes to their repo, which also closes the PR automatically.
- If they don't like it at all, they can simply close the PR too i.e., they reject your proposed change.
- In most cases, they will add comments to the PR to suggest further changes. When that happens, GitHub will notify you.
You can update the PR along the way too. Suppose PR reviewers suggested a certain improvement to your proposed code. To update your PR as per the suggestion, you can simply modify the code in your local repo, commit the updated code to the same master
branch, and push to your fork as you did earlier. The PR will auto-update accordingly.
Sending PRs using the master
branch is less common than sending PRs using separate branches. For example, suppose you wanted to propose two bug fixes that are not related to each other. In that case, it is more appropriate to send two separate PRs so that each fix can be reviewed, refined, and merged independently. But if you send PRs using the master
branch only, both fixes (and any other change you do in the master
branch) will appear in the PRs you create from it.
To create another PR while the current PR is still under review, create a new branch (remember to switch back to the master
branch first), add your new proposed change in that branch, and create a new PR following the steps given above.
It is possible to create PRs within the same repo e.g., you can create a PR from branch feature-x
to the master
branch, within the same repo. Doing so will allow the code to be reviewed by other developers (using PR review mechanism) before it is merged.
Resources
- Now, merge one of the PRs and update the remaining PRs accordingly, as given below:
- Merge one of the PRs on GitHub e.g., Level-8. Remember to choose the
Create merge commit
option when merging. - Pull the updated
master
branch from your fork to your Computer. - Note how the remaining un-merged branches are no longer in sync with the latest
master
. To rectify, merge themaster
branch to each of them. Resolve merge conflicts, if any. - Push the updated branches to your fork. The PRs will update automatically to reflect the updated branch.
- As before, tag the merge commit in the master branch and push the tag to your fork.
- Merge one of the PRs on GitHub e.g., Level-8. Remember to choose the
- Merge the remaining PRs using a procedure similar to the above.
Level-8
: Dates and Times optionalLevel 8. Dates and Times
Teach Duke how to understand dates and times. For example, if the command is deadline return book /by 2/12/2019 1800
, Duke should understand 2/12/2019 1800
as 2nd of December 2019, 6pm, instead of treating it as just a String.
- Minimal: Store deadline dates as a
java.time.LocalDate
in your task objects. Accept dates in a format such asyyyy-mm-dd
format (e.g.,2019-10-15
) and print in a different format such asMMM dd yyyy
e.g., (Oct 15 2019
). - Stretch goal: Use dates and times in more meaningful ways. e.g., add a command to print deadlines/events occurring on a specific date.
Using dates/times in Java
A code snippet using the LocalDate
class:
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
public class Main {
public static void main(String[] args) {
//create dates from strings
LocalDate d1 = LocalDate.parse("2019-12-01");
LocalDate d2 = LocalDate.parse("2019-12-02");
LocalDate d3 = LocalDate.parse("2019-12-02");
//compare dates
System.out.println(d1.isBefore(d2)); // -> true
System.out.println(d1.isAfter(d2)); // -> false
System.out.println(d2.equals(d3)); // -> true
//work with dates
System.out.println(d1.getDayOfWeek()); // -> SUNDAY
System.out.println(d1.getMonth()); // -> DECEMBER
System.out.println(d1.plus(1, ChronoUnit.YEARS)); // -> 2020-12-01
// get today's date and print it in a specific format
LocalDate d4 = LocalDate.now();
System.out.println(d4); // -> 2019-10-15
System.out.println(d4.format(DateTimeFormatter.ofPattern("MMM d yyyy"))); // -> Oct 15 2019
}
}
Level-9
: Find Level 9. Find
Give users a way to find a task by searching for a keyword.
Example:
find book
____________________________________________________________
Here are the matching tasks in your list:
1.[T][✓] read book
2.[D][✓] return book (by: June 6th)
____________________________________________________________
3 Set up a product website
- Add a brief User Guide (UG)
A-UserGuide
: User Guide Add a User Guide to the project. Here is one simple way to do it.
- Update the given
docs\README.md
. See this guide to GitHub flavored Markdown (GFMD). - Go to the settings page of your Duke fork and enable GitHub pages to publish from the
docs
folder (you can select a theme too). - Go to
http://{your username}.github.io/{repo name}/
to view the user guide of your product. Note: it could take 5-10 minutes for GitHub to update the page.
4 Submit the final version Fri, Oct 2nd 2359
-
Soft deadline: midnight before the tutorial
-
Create a new jar file
- Create the JAR file in one of these ways:
- If you have added a GUI or using third-party libraries: use Gradle.
- Else: you can use Intellij.
- The JAR file should be cross-platform and should work in a computer that has Java 11.
- Create the JAR file in one of these ways:
-
Do the following smoke tests to ensure the jar file works (reason: a similar flow will be used when grading your iP).
- Copy the jar file to an empty folder and test it from there. This should surface issues with hard-coded file paths.
- Pass the jar file to team members and ask them to do a test drive. Assuming some of your team members' OS differ from yours, this should verify if the app is cross-platform.
-
Create a new release on GitHub (e.g.,
v0.2
) and upload the JAR file.- Recommended to refrain from uploading multiple JAR files as this can cause extra work for the evaluators.