Skip to content
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

Same poem - Now with Issues and PRs #6

Open
7 tasks
lakruzz opened this issue Feb 12, 2023 · 1 comment
Open
7 tasks

Same poem - Now with Issues and PRs #6

lakruzz opened this issue Feb 12, 2023 · 1 comment

Comments

@lakruzz
Copy link
Member

lakruzz commented Feb 12, 2023

Let's create the same problem again, but this time use some of the tools on GitHub to solve the problem - let's introduce issues and Pull Requests.

Study this code You've already seen most of it before - what do you think is happening?

Run it!

git co master
git pull origin master
cd $(git root)
mkdir pr-lab 

POEM=$(git root)/pr-lab/eeny-meeny-miny-moe.txt

cat <<ENDOFPOEM > $POEM
Eeny, meeny, miny, moe,
Catch a tiger by the toe.
If he hollers, let him go,
Eeny, meeny, miny, moe.

My mother told me to pick 
the very best one and you - are - it!" 
ENDOFPOEM

git add $POEM && git commit -m "I published a poem"
git tag v01.0.0
git pull origin master && git push --tags origin master

Always work on an issue

It's an integrated part of the underlying concepts in both Scrum boards and Kanban boards that work only happens for a reason You could say that any change to the code base must be related to a card that is create in forehand. There's always a pupose!

So consequnently - If we want to improive the poem, we first need an issue (task, user story) that instructs us to do so.

So you should go to the webpage on GitHub (gh browse) for this repo and create new issue - assign it to yourself:

title:    "Fix the Eeeny Meeny poem"
body:     "No rules, just improve whatever you like"
assignee: "@me" 
label:    "bug"
Could have created an issue from the command line?

Of course:

gh issue create \
  --title "Fix the Eeeny Meeny poem" \
  --body "No rules, just improve whatever you like" \
  --assignee "@me" \
  --label "bug"
  • The entire command is one statement but for readability it spawns multiple lines using \ as line-ending on lines that are continued.

It returns the URL to the newly created issue

image

Now create a branch which is specifically related to this particular issue.

image On the icon panel to the left in your VC Code click the GitHub icon. In the lover panel you see the GitHub issues - since you assigned the issue to your selv it should show up - something like:

image

image The Arrow icon will create a new branch, related to this issue.

image The globe will take you to the issue on GitHub in the example (issue 39) the same as gh browse 39.

  • Create a branch on your issue.

NOTE: You terminal might show you, that you are still on master but just hit enter once to get the new status in your prompt.

Could have create a branch from an issue from the command line?

Of course:

# Create a branch off issue no. 39
gh issue develop --checkout 39

Hold on tight I'll show you how we could even have created and the issue and the branch - in one go:

gh issue develop --checkout $(gh issue create \
  --title "Fix the Eeeny Meeny poem" \
  --body "No rules, just improve whatever you like" \
  --assignee "@me" \
  --label "bug" \
  | grep -oP "https:.*\/\\K(\\d+)$")

Quite a few elements makes this command semi-advanced:

The gh issue develop command needs to know the issue number of the one just created - we will get that by parsing the output of the gh issue create command.

  • The entire gh issue create command is wrapped up in Command Substitution $(...)which is passed to the gh issue develop command.
  • The command that created the issue gh issue create is piped | to another command called grep.
  • grep runs a perl-style -P regular expression which is instructed only to return the actual match -o.
  • The regular expression https:.*\/\\K(\\d+)$ is passed as a string, so it must escape the special chars: \/ and \\.
  • The regular expression even shortens the match with a don't look back option \K. Effectively only returning the tailing $ integer from the line which contains https:.

Mind blowing!


Fix the poem

  • Open the new poem (./pr-lab/eeny-meeny-miny-moe.txt) and make some fixes.
  • git add your changes
  • git commit your changes
  • git push your change

HEY - the push wasn't straight forward - you probably got something like:

fatal: The current branch <USER>/issue11 has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin republicdomain/issue11

Calm! Theres nothing in git you can't automate - so of course there is a solution to this issue too. As you might have guessed the solution is a setting in you gitconfig file.

push.default -- read all about it!

The pattern setting you are looking for is probably current.

  • Try this:
git config --file $(git root)/.gitconfig push.default current
git push
  • Go to GitHub and find the commit you just pushed - create a pull request from it!

NOTE: Did you read the output from the git push command - I has a nice surprise!

Could have created a PR from the command line?

Of course:

...See if you can figure it out


@lakruzz lakruzz added the Template Template issue label Feb 12, 2023
@lakruzz lakruzz changed the title Same same - Now with Issues and PRs Same poem - Now with Issues and PRs Feb 12, 2023
@lakruzz
Copy link
Member Author

lakruzz commented Feb 12, 2023

Nice surprise (spoiler)
@republicdomain ➜ /workspaces/sc-republicdomain (republicdomain/issue11) $ git push
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 2 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 385 bytes | 385.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote: 
remote: Create a pull request for 'republicdomain/issue11' on GitHub by visiting:
remote:      https://github.com/kea-classrooms/sc-republicdomain/pull/new/republicdomain/issue11
remote: 
To https://github.com/kea-classrooms/sc-republicdomain
 * [new branch]      republicdomain/issue11 -> republicdomain/issue11
image

@lakruzz lakruzz removed the Template Template issue label Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant