Is There a Way to Automatically Label New Pull Requests in Github Using Pipedream or Github API?

can it be done using Python code?

Currently, Pipedream does not support running Python code directly within the platform. Pipedream components are written in Node.js. However, you can use Python in a separate environment and make API calls to interact with your Pipedream workflows if needed. If you need assistance with a specific use case, please let me know and I’ll be happy to help.

I’m having this error: Cannot read properties of undefined (reading ‘$auth’) using the Node.js code provided above.

I apologize for the confusion. It seems there’s a mistake in the provided code. The correct way to access the GitHub auth token is by using steps.trigger.event.github.$auth.oauth_access_token. Please update the code as follows: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ async run({ steps }) { const token = steps.trigger.event.github.$auth.oauth_access_token; // … rest of the code }, });

I am sstill receiving the same error.

TypeError
Cannot read properties of undefined (reading ‘$auth’)

Here’s the code I’m using:

import { axios } from@pipedream/platform”;

export default defineComponent({
async run({ steps }) {
const token = steps.trigger.event.github.$auth.oauth_access_token;
const pull_request = steps.trigger.event.pull_request;
const repo = steps.trigger.event.repository;
const issue_number = pull_request.number;
const title = pull_request.title;

**const** label_name = pull_request.draft
  ? “CR: [Creator] draft”
  : “CR: [Reviewer] review_needed”;

**const** url = `https://api.github.com/repos/${repo.owner.login}/${repo.name}/issues/${issue_number}/labels`;

**const** headers = {
  Authorization: `Bearer ${token}`,
  “Content-Type”: “application/json”,
};

_// Fetch existing labels_
**const** get_labels_response = **await** axios(**this**, {
  method: “GET”,
  url: url,
  headers: headers,
});
**const** existing_labels = get_labels_response.data;

_// Append the new label to the existing labels list_
**const** labels = existing_labels.map((label) => label.name);
labels.push(label_name);

**const** data = { labels: labels };

**const** response = **await** axios(**this**, {
  method: “POST”,
  url: url,
  headers: headers,
  data: data,
});

**return** response.data;

},
});

I apologize for the confusion earlier. It seems I made an incorrect assumption about the structure of the steps.trigger.event object. To better assist you, could you please provide more information about the trigger you’re using in your workflow? This will help me understand the structure of the steps.trigger.event object and how to access the GitHub auth token correctly.

this is for a workflow for Github where we want to add a label for new pull request that are drafts and will change the label that it is for review when the status is changed that it is ready for review.

To create a workflow that adds a label to new draft pull requests and updates the label when the status changes to “ready for review”, you can use the “New or Updated Pull Request (Instant)” trigger and a code step to add or update the label. Here’s an example workflow: 1. Add the “New or Updated Pull Request (Instant)” trigger from the GitHub app. 2. Connect your GitHub account and select the desired repository. 3. Add a code step with the following code: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ async run({ steps }) { const token = steps.trigger.event.authorization.token; const pull_request = steps.trigger.event.pull_request; const repo = steps.trigger.event.repository; const issue_number = pull_request.number; const title = pull_request.title; const label_name = pull_request.draft ? “CR: [Creator] draft” : “CR: [Reviewer] review_needed”; const url = https://api.github.com/repos/${repo.owner.login}/${repo.name}/issues/${issue_number}/labels; const headers = { Authorization: Bearer ${token}, “Content-Type”: “application/json”, }; // Fetch existing labels const get_labels_response = await axios(this, { method: “GET”, url: url, headers: headers, }); const existing_labels = get_labels_response.data; // Append the new label to the existing labels list const labels = existing_labels.map((label) => label.name); labels.push(label_name); const data = { labels: labels }; const response = await axios(this, { method: “POST”, url: url, headers: headers, data: data, }); return response.data; }, });

I am receiving this error:

TypeError
Cannot read properties of undefined (reading ‘token’)

I apologize for the confusion earlier. It seems I made an incorrect assumption about the structure of the steps.trigger.event object. Since you’re using a GitHub trigger, you should access the OAuth access token using steps.trigger.event.authorization.token. Please update your code as follows: ```
import { axios } from “@pipedream/platform”; export default defineComponent({ async run({ steps }) { const token = steps.trigger.event.authorization.token; // … rest of the code remains the same }, });

I still have the same error:

TypeError
Cannot read properties of undefined (reading ‘token’)
DETAILS

    at Object.run (file:///tmp/__pdg__/dist/code/45d4129ab567a9e28a65db591928b865dd2a5a0fa0ff390652c2e8a749e1d46a/component.mjs:5:53)
    at null.executeComponent (/var/task/launch_worker.js:229:53)
    at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)

Timestamp
9/16/2023, 1:56:13 AMDuration
2ms

github_1

CONFIGURE

CODE

RESULTS