Module 03 · Final Project and Assessment最终项目与评估
Practice Project: Part 1 - GitHub UI实践项目:第 1 部分 - GitHub 界面
Estimated Time: 30 minutes
预计时间:30 分钟
Overview 概述
In this lab you will start your journey with the GitHub implemention for your organisation by creating a repository in your GitHub account and then initialising the repository with a README.md file and a License. Following this, you'll update the README file to include a Code of Conduct and Contribution Guidelines markdown files. After making these changes, you'll commit the files to your repository.
在这个实验室,您将从为您的组织在 GitHub 上创建一个仓库开始您的旅程,然后使用 README.md 文件和许可证初始化该仓库。随后,您将更新 README 文件,包括行为准则和贡献指南的 markdown 文件。在这些更改完成后,您将提交文件到您的仓库。
Next, you'll create a new branch and add code for Shipping logistics calculation. To wrap up, you'll merge this branch into the main branch using a Pull Request.
接下来,您将创建一个新的分支并添加关于物流计算的代码。最后,您将通过 Pull Request 将这个分支合并到主分支中。
Objectives 目标
After completing this lab, you will have demonstrated that you can:
完成这个实验室后,你将证明你能够:
- Create a repository with a README.md file and a license.
创建一个包含 README.md 文件和许可证的仓库。 - Update the existing files.
更新现有文件。 - Commit the files to your repository.
将文件提交到您的仓库。 - Create a new branch and add files to it.
创建一个新的分支并将文件添加到其中。 - Merge this branch to the main branch using a Pull Request.
将此分支合并到主分支,使用 Pull Request 进行。
Task 1: Create a repository with a README file and a license. 任务 1:创建一个包含 README 文件和许可证的仓库。
-
At the top right of the GitHub home page, click on the
+icon and selectNew repository.
在 GitHub 首页的右上角,点击+图标并选择New repository。 -
Create a new GitHub repository called
LogisticsShippingRatesand make sure that it is Public.
创建一个新的 GitHub 仓库,命名为LogisticsShippingRates,并确保它是公开的。 -
Select the Add a README file field. Click on the Choose a license field and select
Apache License 2.0from the drop down. Finally, click on Create repository.
选择“添加 README 文件”字段。点击“选择许可证”字段并从下拉菜单中选择Apache License 2.0。最后,点击“创建仓库”。 -
After successfully creating a new repo, you will see the following screenshot.
创建新仓库成功后,您将看到以下截图。
Your repository is created and includes the README and LICENSE files. Now, you are ready to update your repository files to include useful information for your community.
您的仓库已创建,并包含 README 和 LICENSE 文件。现在,您可以更新仓库文件,以便为您的社区提供有用信息。
Task 2: Update the README file. 任务 2:更新 README 文件。
-
Click on
README.mdfile to open it and click the pencil icon to edit it.
点击README.md文件打开它,然后点击铅笔图标进行编辑。 -
Add the following information to the file:
请将以下信息添加到文件中:
Please consider the below factors while contributing
Code Style:
Maintain a consistent code style for readability.
Documentation:
Ensure well-documented code for effective collaboration.
Testing:
Thoroughly test your changes before submitting a pull request.
Issue Tracker:
Check the Issue Tracker for tasks.
Code Review:
All contributions undergo a code review process.
Licensing:
Contributions are licensed.
-
Now click on
Commit changes现在点击Commit changes -
Ensure that the radio button to commit directly to the main/master branch is selected. Add a commit message and click on
Commit Changes
确保选中直接提交到主/主分支的单选按钮。添加提交信息并点击Commit Changes
NOTE: After completing the steps in each of the tasks, if you are unable to see the options depicted in the provided screenshots, click on the
Codeoption as highlighted in below screenshot:
注意:完成每个任务中的步骤后,如果您看不到提供的截图中的选项,请点击以下截图中所突出显示的Code选项:
Task 3: Add a code of conduct. 任务 3:添加行为准则。
A code of conduct helps set ground rules for the behavior of your project's participants. It defines standards for how to engage in a community.
行为准则有助于为项目参与者的行为设定基本规则。它定义了如何在社区中参与的标准。
GitHub provides templates for common codes of conduct to help you quickly add one to your project.
GitHub 提供了常见行为准则的模板,以帮助您快速将其中一个添加到您的项目中。
-
To create a new file click on Add file and then
Create New File.
创建新文件,请点击“添加文件”,然后Create New File。 -
Add a new file named
CODE_OF_CONDUCT.mdto the root folder of the repository. The Choose a code of conduct template button is displayed.
将名为CODE_OF_CONDUCT.md的新文件添加到仓库的根目录中。显示“选择行为准则模板”按钮。 -
Click the Choose a code of conduct template button. You will see a popup mentioning you may lose unsaved changes. Click on
OK.
点击“选择行为准则模板”按钮。您将看到一个弹出窗口提示您可能会丢失未保存的更改。点击OK。 -
Click on
Contributor Covenantto load this template. Then clickReview and submitto add the file to your project.
点击Contributor Covenant加载此模板。然后点击Review and submit将文件添加到您的项目中。 -
Scroll down the page to read the content. Click on
Commit changes.
向下滚动页面阅读内容。点击Commit changes。 -
Ensure that the radio button to Commit directly to the main/master branch is selected and click
Commit changes.
确保选中直接提交到主/主分支的单选按钮,然后点击Commit changes。
NOTE: In the past the default branch in your GitHub repo used the name
master. Effective Oct 1. 2020, all new GitHub repositories use the more inclusive termmainas the name of the default branch instead ofmaster.
注意:过去在您的 GitHub 仓库中,默认分支的名称为master。自 2020 年 10 月 1 日起,所有新的 GitHub 仓库将使用更具包容性的术语main作为默认分支的名称,而不是master。
If the page is zoomed in, you may see only the Commit changes button and not the radio button. Zoom out or scroll down to see the radio button.
如果页面被放大,您可能只能看到“提交更改”按钮,而看不到单选按钮。缩小页面或向下滚动以查看单选按钮。
- Your project now contains a code of conduct.
您的项目现在包含了一项行为准则。
Task 4: Establish contribution guidelines. 任务 4:建立贡献指南。
Contribution guidelines provide clear instructions for individuals looking to contribute to the project. To implement these guidelines, please follow these steps:
贡献指南为希望为项目做出贡献的个人提供了明确的指示。为了实施这些指南,请按照以下步骤操作:
- Create a new file in the repository's root directory and name it
CONTRIBUTING.md.
创建一个新文件在仓库的根目录下,并命名为CONTRIBUTING.md。 - Inside the file, include the following information:
在文件中包含以下信息:
Contribution guidelines
Welcome Contributors!
Thank you for considering contributing to the centralized repository. This document outlines the guidelines for contributing to the development of Shipping Rates and Calculations.
Code style
Please follow the coding style and conventions used in the existing codebase. This helps maintain consistency across the project.
Documentation
Ensure that your contributions are well-documented. Include comments in your code where necessary and provide a clear and concise description of your changes in the pull request.
Testing
Before submitting a pull request, make sure your changes have been tested thoroughly. Include relevant test cases and ensure that existing tests pass.
Issue tracker
Check the issue tracker for any open issues or feature requests. If you're working on something, please comment on the issue to let others know.
Code review
All contributions will go through a code review process. Be open to feedback and be willing to make changes if necessary. Code reviews help maintain code quality and consistency.
Thank you for your contribution!
-
Commit this file to your repository.
将此文件提交到您的仓库。 -
Click on
Codeto go to the repository home page.
点击Code进入仓库主页。
Your project now contains Contribution Guidelines as well.
您的项目现在包含贡献指南了。
Task 5: Create a new branch. 任务 5:创建一个新的分支。
-
Click on
branchin your repository.
点击您仓库中的branch。 -
Now, click on
New Branchand enter the branch name asShipping_Calculation, then clickCreate New Branch
现在,点击New Branch,输入分支名称为Shipping_Calculation,然后点击Create New Branch
This will be used for adding your Shipping Calculation code.
此用于添加您的运费计算代码。
Task 6: Add the Shipping Calculation code in this branch. 任务 6:在此分支中添加运费计算代码。
-
Change to the
Shipping_Calculationbranch by selecting it from the dropdown.
切换到Shipping_Calculation分支,通过从下拉菜单中选择它。 -
Create a new file named
Shipping_Cost_Calculator.py.
创建一个名为Shipping_Cost_Calculator.py的新文件。 -
Add the following code in the new file:
在新的文件中添加以下代码:
# Shipping Cost Calculator
## Input package weight and shipping rate
weight = float(input("Enter the package weight in kilograms: "))
rate = float(input("Enter the shipping rate per kilogram: "))
## Calculate shipping cost
shipping_cost = weight * rate
## Display the result
print(f"Shipping Cost: {shipping_cost} USD")
- Ensure that the radio button to Commit directly to the Shipping_Calculation branch is selected and click
Commit changes.
确保选中直接提交到 Shipping_Calculation 分支的单选按钮,并点击Commit changes。
The Shipping_Calculation branch now contains the Shipping_Cost_Calculator.py file.
Shipping_Calculation 分支现在包含 Shipping_Cost_Calculator.py 文件。
Task 7: Create a pull request to the main branch. 任务 7:向主分支创建一个拉取请求。
-
Go to the
Pull requesttab and click onCompare & pull request.
前往Pull request标签并点击Compare & pull request。 -
Add an appropriate commit message and click on
Create pull request.
添加适当的提交信息并点击Create pull request。
Task 8: Merge the branch to the main branch. 任务 8:将分支合并到主分支。
-
Click on
Merge pull request. 点击Merge pull request。 -
Click on
Confirm merge. 点击Confirm merge。 -
The successfully merged changes will be shown in the Github UI as below:
成功合并的更改将在以下 Github 界面中显示: -
You will see the below message once the branch is merged.
您将在分支合并后看到以下信息。 -
Check to see that your project now contains the
Shipping_Cost_Calculator.pyfile as well.
检查一下,您的项目现在是否包含Shipping_Cost_Calculator.py文件。
Congratulations 祝贺
In this lab you have created a repository in your GitHub account with a README.md file and a License. You have then edited the README file and added Code of Conduct, and Contribution Guidelines. Further, you have commited these files to your repository. Finally, you have added the Shipping logistics calculator file to a new branch, and merged it to the main branch using a Pull Request.
在这个实验室中,您已在 GitHub 账户中创建了一个存储库,其中包含 README.md 文件和许可证。然后,您编辑了 README 文件,并添加了行为准则和贡献指南。进一步地,您将这些文件提交到您的存储库。最后,您将物流计算器文件添加到新分支,并通过 Pull Request 将其合并到主分支。