Skip to content

Commit

Permalink
Merge pull request github#36153 from github/repo-sync
Browse files Browse the repository at this point in the history
Repo sync
  • Loading branch information
docs-bot authored Feb 3, 2025
2 parents 9c91228 + 9ea1545 commit a810815
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ shortTitle: Contribute to open source
---
## Discovering relevant projects

If there's a particular topic that interests you, visit `github.com/topics/<topic>`. For example, if you are interested in machine learning, you can find relevant projects and good first issues by visiting https://github.com/topics/machine-learning. You can browse popular topics by visiting [Topics](https://github.com/topics). You can also search for repositories that match a topic you're interested in. For more information, see [AUTOTITLE](/search-github/searching-on-github/searching-for-repositories#search-by-topic).
If there's a particular topic that interests you, visit `github.com/topics/<topic>`. For example, if you are interested in machine learning, you can find relevant projects and good first issues by visiting https://github.com/topics/machine-learning. You can browse popular topics by visiting [Topics](https://github.com/topics). You can also search for repositories that match a topic you're interested in. See [AUTOTITLE](/search-github/searching-on-github/searching-for-repositories#search-by-topic).

If you're interested in contributing to projects that **reduce the carbon emissions of software**, review [{% data variables.product.github %}'s Green Software Directory](https://github.com/github/GreenSoftwareDirectory).

If you've been active on {% data variables.product.prodname_dotcom %}, you can find personalized recommendations for projects and good first issues based on your past contributions, stars, and other activities in [Explore {% data variables.product.prodname_dotcom %}](https://github.com/explore).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ You can search, sort, and filter your starred repositories and topics on your {%
Starring makes it easy to find a repository or topic again later. You can see all the repositories and topics you have starred by going to your {% data variables.explore.your_stars_page %}.

{% ifversion fpt or ghec %}
You can star repositories and topics to discover similar projects on {% data variables.product.github %}. When you star repositories or topics, {% data variables.product.github %} may recommend related content on your personal dashboard. For more information, see [AUTOTITLE](/get-started/exploring-projects-on-github/finding-ways-to-contribute-to-open-source-on-github) and [AUTOTITLE](/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-user-account-settings/about-your-personal-dashboard#staying-updated-with-activity-from-the-community).
You can star repositories and topics to discover similar projects on {% data variables.product.github %}. For example, after you star [{% data variables.product.github %}'s Green Software Directory](https://github.com/github/GreenSoftwareDirectory), you will see other content related to green software on your personal dashboard.
{% endif %}

Starring a repository also shows appreciation to the repository maintainer for their work. Many of {% data variables.product.prodname_dotcom %}'s repository rankings depend on the number of stars a repository has. In addition, [Explore {% data variables.product.prodname_dotcom %}](https://github.com/explore) shows popular repositories based on the number of stars they have.
Expand Down
1 change: 1 addition & 0 deletions content/get-started/learning-to-code/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ versions:
fpt: '*'
children:
- /reusing-other-peoples-code-in-your-projects
- /learning-to-debug-with-github-copilot
shortTitle: Learn to code
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
---
title: Learning to debug with GitHub Copilot
intro: 'Identify and fix errors in your code by asking {% data variables.product.prodname_copilot %} for help.'
topics:
- Copilot
versions:
fpt: '*'
shortTitle: Debug with Copilot
---

Finding and fixing bugs in code can be frustrating, especially when you're a new developer. Thankfully, tools like {% data variables.product.prodname_copilot %} can quickly identify and squash bugs, letting you focus on more creative, interesting work.

## Prerequisites

The examples in this article assume you're using {% data variables.product.prodname_copilot %} to debug a Python project in {% data variables.product.prodname_vscode %} ({% data variables.product.prodname_vscode_shortname %}). To follow the examples, you need to:
* Complete [Set up {% data variables.product.prodname_vscode %} with {% data variables.product.prodname_copilot_short %}](https://code.visualstudio.com/docs/copilot/setup-simplified) in the {% data variables.product.prodname_vscode %} documentation.
* [Download Python](https://www.python.org/downloads/).
* Install the [Python extension for {% data variables.product.prodname_vscode %}](https://marketplace.visualstudio.com/items?itemName=ms-python.python).

## Learning to debug through examples

There are two main situations you'll encounter when you try to run bugged code:

* Your code exits before it finishes running, and you receive an error message.
* Your code runs without errors, but the output is different from what you expected.

Thankfully, {% data variables.product.prodname_copilot_short %} can help debug your code in both situations. To learn how, work through the following examples.

### Debugging an error with {% data variables.product.prodname_copilot %}

When you run bugged code, you'll often receive an error message. The message tells you the file and line where the error occurred and briefly describes what went wrong. However, error messages can be confusing. To fully understand and fix the bug, we can ask {% data variables.product.prodname_copilot_short %} for help.

Let's try this out with the [`bugged_dice_battle.py`](https://github.com/new2code/debug-with-copilot/blob/main/bugged_dice_battle.py) file in the [`new2code/debug-with-copilot`](https://github.com/new2code/debug-with-copilot) repository. This program simulates a dice battle between two players using the following code:

```python
# Import the random module to easily generate pseudo-random numbers
import random

# Define a function that simulates a dice battle between two players
def dice_battle():

# Generate random numbers between 1 and 6 for each player's die roll
die_1 = random.randint(1, 6)
die_2 = random.randint(1, 6)

# Compare the die rolls and return the result as a string
if die_1 > die_2:
return "Player 1 rolled a " + die_1 + " and Player 2 rolled a " + die_2 + ". Player 1 wins!"
elif die_1 < die_2:
return "Player 1 rolled a " + die_1 + " and Player 2 rolled a " + die_2 + ". Player 2 wins!"
else:
return "Player 1 rolled a " + die_1 + " and Player 2 rolled a " + die_2 + ". It's a tie!"

print(dice_battle())
```

First, we need to clone the repository locally:
1. In {% data variables.product.prodname_vscode_shortname %}, open the Command Palette by pressing <kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> (Mac) or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> (Windows/Linux).
1. Type `Git: Clone` and press <kbd>Enter</kbd>.
1. Paste the URL of the `new2code/debug-with-copilot` repository:

```text copy
https://github.com/new2code/debug-with-copilot
```

1. Press <kbd>Enter</kbd>, then choose a location to save the repository on your computer.
1. When prompted, open the repository in {% data variables.product.prodname_vscode_shortname %}.

Now that we've cloned the repository, let's run `bugged_dice_battle.py` to see the output:

1. Open the Command Palette by pressing <kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> (Mac) or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> (Windows/Linux).
1. Type `Terminal: Create New Terminal` and press <kbd>Enter</kbd>.
1. If you are using Mac or Linux, in the terminal tab, paste the following code:

```shell copy
python bugged_dice_battle.py
```

Otherwise, if you are using Windows, paste the following code:

```shell copy
py bugged_dice_battle.py
```

1. Press <kbd>Enter</kbd> to run the program.

Unfortunately, we get some error text in our terminal ending with the following message: `TypeError: can only concatenate str (not "int") to str`. To understand what this means, press <kbd>Command</kbd>+<kbd>Shift</kbd>+<kbd>I</kbd> (Mac) or <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>I</kbd> (Windows/Linux) to open {% data variables.product.prodname_copilot_chat_short %}, then paste and send the following prompt:

```text copy
Explain in depth why my code produces the following error and how I can fix it:
TypeError: can only concatenate str (not "int") to str
```

{% data variables.product.prodname_copilot_short %} will respond that the error occurs because we are trying to concatenate the integers `die_1` and `die_2` to strings, and you can only concatenate strings to strings. It will then provide an updated version of our code that fixes the bug by using the `str()` function to convert the integers to strings before concatenating them.
### Debugging an incorrect output with {% data variables.product.prodname_copilot %}
Sometimes, bugged code runs without throwing any errors, but the output is clearly incorrect. In this case, debugging can be more difficult because {% data variables.product.prodname_vscode_shortname %} can't tell you the location or description of the bug.
For these "invisible" bugs, {% data variables.product.prodname_copilot_short %} is particularly useful. Let's get some hands-on experience using the [`bugged_factorial_finder.py`](https://github.com/new2code/debug-with-copilot/blob/main/bugged_factorial_finder.py) file in the [`new2code/debug-with-copilot`](https://github.com/new2code/debug-with-copilot) repository. The Python program is supposed to calculate a factorial, and it contains the following code:
```python
# Initialize the factorial result to 1
factorial = 1

# Initialize the input number to 6
number = 6

# Loop from 1 to number (inclusive) and multiply factorial by each number
for i in range(1, number + 1):
factorial *= factorial * i

print(f"The factorial of {number} is {factorial}")
```
Since we've already cloned the repository locally, let's run `bugged_factorial_finder.py` to see the output:
1. In {% data variables.product.prodname_vscode_shortname %}, open the Command Palette by pressing <kbd>Cmd</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> (Mac) or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> (Windows/Linux).
1. Type `Terminal: Create New Terminal` and press <kbd>Enter</kbd>.
1. If you are using Mac or Linux, in the terminal tab, paste the following code:
```shell copy
python bugged_factorial_finder.py
```
Otherwise, if you are using Windows, paste the following code:
```shell copy
py bugged_factorial_finder.py
```
1. Press <kbd>Enter</kbd> to run the program.
Unfortunately, the code isn't working as expected. We want it to return `720`, the correct value of 6 factorial, but the output is much higher than that.
To understand what went wrong, with the `bugged_factorial_finder.py` file open in {% data variables.product.prodname_vscode_shortname %}, open {% data variables.product.prodname_copilot_chat_short %} and send the following prompt:
```text copy
Why is the output of this code so much higher than expected? Please explain in depth and suggest a solution.
```
{% data variables.product.prodname_copilot_short %} will point out that, because we're using the `*=` operator, we're actually multiplying `factorial` by both `i` **and** `factorial`. In other words, we're multiplying by an extra `factorial` for each iteration of the loop.
To fix this error, {% data variables.product.prodname_copilot_short %} will suggest code that removes the extra `factorial` from the equation, or that changes the `*=` operator to `=`.
## Debugging your own project
Now that you've practiced debugging some simple programs with {% data variables.product.prodname_copilot_short %}, you can use the same methodologies to find and fix bugs hiding in your own work.
For example, to debug an error message generated by your code, send {% data variables.product.prodname_copilot_short %} the following prompt:
```text copy
Explain in depth why my code produces the following error and how I can fix it:
YOUR-ERROR-MESSAGE
```
Otherwise, if you're debugging an incorrect output, ask {% data variables.product.prodname_copilot_short %} why the output is incorrect and how you can fix it. For the best results, provide as much context as possible on how the output differs from your expectations.
With these tactics, you're well equipped to start squashing bugs in your project!
## Next steps
As you continue coding, you'll likely encounter specific problem scenarios and errors that are difficult to debug. For a list of potential issues and example {% data variables.product.prodname_copilot_chat_short %} prompts to fix them, see [AUTOTITLE](/copilot/example-prompts-for-github-copilot-chat/debugging-errors).
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ Once you star repositories or follow people, you will see updates on their activ
## Search for a topic or project on {% data variables.product.github %}

1. Navigate to https://github.com/search.
1. Type a keyword or query into the search bar. {% ifversion fpt or ghec %}For example, try "how to build a webpage", or "skills-course".{% endif %} For more detailed information on how to search {% data variables.product.github %} for specific topics, repositories, or code, see [AUTOTITLE](/search-github/getting-started-with-searching-on-github/about-searching-on-github).
1. Use the left sidebar to filter the results. {% ifversion fpt or ghec %}For example, to browse all repositories in the "skills-course" topic, search "skills-course", then filter by "Topic".{% endif %}
1. Star the repositories that match your interests.
1. Type a keyword or query into the search bar. For example, try "green software tools." For more detailed information about searching for specific topics, repositories, or code, see [AUTOTITLE](/search-github/getting-started-with-searching-on-github/about-searching-on-github).
1. Use the left sidebar to filter the results. For example, to browse all repositories in the "green-software" topic, search "green-software", then filter by "Topic".
1. Star the repositories that match your interests, such as [{% data variables.product.github %}'s Green Software Directory](https://github.com/github/GreenSoftwareDirectory).

## Following people and organizations on {% data variables.product.github %}

Expand Down
2 changes: 2 additions & 0 deletions content/rest/enterprise-admin/billing.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ autogenerated: rest

The `manage_billing:enterprise` scope is required for {% data variables.product.pat_v1_plural %} to access these endpoints.

> [!IMPORTANT] The API currently supports adding or removing up to 50 resources in a single operation.
<!-- Content after this section is automatically generated -->

0 comments on commit a810815

Please sign in to comment.