筆者已經使用 Jenkins 一段時間了,這次有部分內容需要調整,於是又回來翻了翻文件,看到 Jenkins 的 git 套件說明頁面有個小小的拼寫錯誤:
文中內容如下:
但其實這段程式碼是錯誤的, main 後面還需要有一個單引號(Single Quote),正確內容如下:
因為 Jenkins 是開源專案,他底下的 git 套件應該也會是開源的吧? 如果是的話我們就可以修改程式碼,並且發起拉取請求(Pull Requests, PR),也就是請對方將我們的程式碼合併到原始專案中,修正這個小小的錯誤,為這個專案做出貢獻。
在這個網站中找不到程式碼儲存庫的網站連結,不過直接用 google 搜尋 jenkins git plugin 出來的第一個網站一眼就可以看到 GitHub 連結:
開啟 GitHub 專案:
在專案中直接搜尋關鍵字,很幸運的就找到了有問題的地方,確實是就是我們要找的專案:
接下來就是要準備修改程式了,先點選「Fork」,將專案複製一份到自己的帳號中:
直接點選 Create fork
因為已經複製一份到自己的帳號中了,接下來就是和平常使用 github 一樣,在自己的儲存庫中操作,修改程式碼後 commit 和 push 到 GitHub 中。
修改完程式碼、推送到 GitHub 後接下來就要回到 GitHub 網站繼續 PR 的流程。
在專案中會看到 Compare & pull request 的按鈕, 直接點選 Compare & pull request
會出現比對內容的頁面,需要填寫拉取請求的標題和內容。
筆者這次示範的這個專案算是大型專案,有許多人貢獻,已經有設定預設內容,讓新的貢獻者快速了解貢獻需要注意的地方。 所以一進來就會有很多文字:
這個專案的注意事項如下:
簡單來說就是需要另開分支,不要直接在主分支中操作(為了符合要求於是筆者又從頭開始,建立另一個分支 commit 一次)、 需要有良好的 commit 訊息、 要有問題連結。
看起來有點難,所以我們直接去其他 Pull Requests 中找已經被關閉(Closed)且被接受的(Merged Pull Request) ,看看這些 PR 被接受的「成功案例」:
在這之中筆者找到了一個內容滿簡短的 PR:
最前面有使用 [JENKINS-73677] 這樣的內容標記,一看就是某個問題回報系統的問題單號,點進連結一看,確實是如此:
為了增加 PR 被接受的機率,筆者也在這個 Jenkins issues 中提了一個 Issues,並且標記分配給自己:
拿著這個議題單號和連結,再仿照別人的 PR 撰寫內容,寫完後按下 Create pull request 正式發起 PR
接下來就是漫長的等待,等待這個專案有權限的使用者來審核:
很幸運的,很快就有人來審核,將程式碼合併:
就這樣,又成功的為一個專案做出了貢獻(雖然只有兩個字):
參考資料:
GitHub jenkinsci/git-plugin - [JENKINS-75311] Add closing quote in checkout scmGit branches example #1723
Jenkins.Issues - [JENKINS-75311] Fix syntax error in checkout scmGit example in help
文中內容如下:
checkout scmGit(branches: [[name: 'main]],
userRemoteConfigs: [[url: 'https://git-server/user/repository.git']])
但其實這段程式碼是錯誤的, main 後面還需要有一個單引號(Single Quote),正確內容如下:
checkout scmGit(branches: [[name: 'main']],
userRemoteConfigs: [[url: 'https://git-server/user/repository.git']])
因為 Jenkins 是開源專案,他底下的 git 套件應該也會是開源的吧? 如果是的話我們就可以修改程式碼,並且發起拉取請求(Pull Requests, PR),也就是請對方將我們的程式碼合併到原始專案中,修正這個小小的錯誤,為這個專案做出貢獻。
在這個網站中找不到程式碼儲存庫的網站連結,不過直接用 google 搜尋 jenkins git plugin 出來的第一個網站一眼就可以看到 GitHub 連結:
開啟 GitHub 專案:
在專案中直接搜尋關鍵字,很幸運的就找到了有問題的地方,確實是就是我們要找的專案:
接下來就是要準備修改程式了,先點選「Fork」,將專案複製一份到自己的帳號中:
直接點選 Create fork
因為已經複製一份到自己的帳號中了,接下來就是和平常使用 github 一樣,在自己的儲存庫中操作,修改程式碼後 commit 和 push 到 GitHub 中。
修改完程式碼、推送到 GitHub 後接下來就要回到 GitHub 網站繼續 PR 的流程。
在專案中會看到 Compare & pull request 的按鈕, 直接點選 Compare & pull request
會出現比對內容的頁面,需要填寫拉取請求的標題和內容。
筆者這次示範的這個專案算是大型專案,有許多人貢獻,已經有設定預設內容,讓新的貢獻者快速了解貢獻需要注意的地方。 所以一進來就會有很多文字:
這個專案的注意事項如下:
<!-- Please describe your pull request here. -->
### Testing done
<!-- Comment:
Provide a clear description of how this change was tested.
At minimum this should include proof that a computer has executed the changed lines.
Ideally this should include an automated test or an explanation as to why this change has no tests.
Note that automated test coverage is less than complete, so a successful PR build does not necessarily imply that a computer has executed the changed lines.
If automated test coverage does not exist for the lines you are changing, you must describe the scenario(s) in which you manually tested the change.
For frontend changes, include screenshots of the relevant page(s) before and after the change.
For refactoring and code cleanup changes, exercise the code before and after the change and verify the behavior remains the same.
-->
### Submitter checklist
- [ ] Make sure you are opening from a **topic/feature/bugfix branch** (right side) and not your main branch!
- [ ] Ensure that the pull request title represents the desired changelog entry
- [ ] Please describe what you did
- [ ] Link to relevant issues in GitHub or Jira
- [ ] Link to relevant pull requests, esp. upstream and downstream changes
- [ ] Ensure you have provided tests - that demonstrates feature works or fixes the issue
<!--
Put an x into the [ ] to show you have filled the information.
The template comes from https://github.com/jenkinsci/.github/blob/master/.github/pull_request_template.md
You can override it by creating .github/pull_request_template.md in your own repository
-->
簡單來說就是需要另開分支,不要直接在主分支中操作(為了符合要求於是筆者又從頭開始,建立另一個分支 commit 一次)、 需要有良好的 commit 訊息、 要有問題連結。
看起來有點難,所以我們直接去其他 Pull Requests 中找已經被關閉(Closed)且被接受的(Merged Pull Request) ,看看這些 PR 被接受的「成功案例」:
在這之中筆者找到了一個內容滿簡短的 PR:
最前面有使用 [JENKINS-73677] 這樣的內容標記,一看就是某個問題回報系統的問題單號,點進連結一看,確實是如此:
為了增加 PR 被接受的機率,筆者也在這個 Jenkins issues 中提了一個 Issues,並且標記分配給自己:
拿著這個議題單號和連結,再仿照別人的 PR 撰寫內容,寫完後按下 Create pull request 正式發起 PR
接下來就是漫長的等待,等待這個專案有權限的使用者來審核:
很幸運的,很快就有人來審核,將程式碼合併:
就這樣,又成功的為一個專案做出了貢獻(雖然只有兩個字):
參考資料:
GitHub jenkinsci/git-plugin - [JENKINS-75311] Add closing quote in checkout scmGit branches example #1723
Jenkins.Issues - [JENKINS-75311] Fix syntax error in checkout scmGit example in help
留言
張貼留言
如果有任何問題、建議、想說的話或文章題目推薦,都歡迎留言或來信: a@ruyut.com