kea-dev / social-coding

https://docs.kea.dev/posts/social-coding/
0 stars 1 forks source link

Same poem - Now with Issues and PRs #6

Open lakruzz opened 1 year ago

lakruzz commented 1 year ago

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.

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: ```shell # 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

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.

git config --file $(git root)/.gitconfig push.default current
git push

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](https://cli.github.com/manual/) ---
lakruzz commented 1 year ago
Nice surprise (spoiler) ```shell @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