Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions docs/content/docs/reference/components/github_v1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,126 @@ Type: OBJECT
```


### Create Pull Request
Name: createPullRequest

`Creates a new pull request.`

#### Properties

| Name | Label | Type | Description | Required |
|:---------------:|:--------------:|:------------:|:-------------------:|:--------:|
| owner | User/Organization | STRING | The owner of the repository (user or organization). | true |
| repository | Repository | STRING | Repository where new pull request will be created. | true |
| title | Title | STRING | Title of the new pull request. | false |
| body | Body | STRING | The contents of the pull request. | false |
| head | Head | STRING | The name of the branch where your changes are implemented. For cross-repository pull requests in the same network, namespace head with a user like this: username:branch. | true |
| head_repo | Head Repo | STRING | The name of the repository where the changes in the pull request were made. This field is required for cross-repository pull requests if both repositories are owned by the same organization. | false |
| base | Base | STRING | The name of the branch you want the changes pulled into. This should be an existing branch on the current repository. You cannot submit a pull request to one repository that requests a merge to a base of another repository. | true |
| issue | Issue | INTEGER | An issue in the repository to convert to a pull request. The issue title, body, and comments will become the title, body, and comments on the new pull request. Required unless title is specified. | false |
| draft | Draft | BOOLEAN <details> <summary> Options </summary> <span>true</span>, <span>false</span> </details> | Indicates whether the pull request is a draft. | true |

#### Example JSON Structure
```json
{
"label" : "Create Pull Request",
"name" : "createPullRequest",
"parameters" : {
"owner" : "",
"repository" : "",
"title" : "",
"body" : "",
"head" : "",
"head_repo" : "",
"base" : "",
"issue" : 1,
"draft" : false
},
"type" : "github/v1/createPullRequest"
}
```

#### Output



Type: OBJECT


#### Properties

| Name | Type | Description |
|:------------:|:------------:|:-------------------:|
| url | STRING | The URL of the created pull request. |
| id | INTEGER | ID of the created pull request. |
| node_id | STRING | |
| html_url | STRING | |
| diff_url | STRING | |
| patch_url | STRING | |
| issue_url | STRING | |
| commits_url | STRING | |
| review_comment_url | STRING | |
| comments_url | STRING | |
| statuses_url | STRING | |
| number | INTEGER | Number uniquely identifying the pull request within its repository. |
| state | STRING | The state of the pull request. Either open or closed. |
| locked | BOOLEAN <details> <summary> Options </summary> <span>true</span>, <span>false</span> </details> | |
| title | STRING | The title of the pull request. |
| user | OBJECT <details> <summary> Properties </summary> &#123;STRING\(login), STRING\(id), STRING\(html_url), STRING\(type)&#125; </details> | A GitHub user. |
| body | STRING | The contents of the pull request. |
| labels | ARRAY <details> <summary> Items </summary> [&#123;STRING\(id), STRING\(name), STRING\(description)&#125;] </details> | |
| comments | INTEGER | The number of comments on the pull request. |
| review_comments | INTEGER | The number of comments for review on the pull request. |
| maintainer_can_modify | BOOLEAN <details> <summary> Options </summary> <span>true</span>, <span>false</span> </details> | Indicates whether maintainers can modify the pull request. |
| commits | INTEGER | The number of commits in the pull request. |
| additions | INTEGER | The number of additions in the pull request. |
| deletions | INTEGER | The number of deletions in the pull request. |
| changed_files | INTEGER | The number of changed files in the pull request. |




#### Output Example
```json
{
"url" : "",
"id" : 1,
"node_id" : "",
"html_url" : "",
"diff_url" : "",
"patch_url" : "",
"issue_url" : "",
"commits_url" : "",
"review_comment_url" : "",
"comments_url" : "",
"statuses_url" : "",
"number" : 1,
"state" : "",
"locked" : false,
"title" : "",
"user" : {
"login" : "",
"id" : "",
"html_url" : "",
"type" : ""
},
"body" : "",
"labels" : [ {
"id" : "",
"name" : "",
"description" : ""
} ],
"comments" : 1,
"review_comments" : 1,
"maintainer_can_modify" : false,
"commits" : 1,
"additions" : 1,
"deletions" : 1,
"changed_files" : 1
}
```


### Get Issue
Name: getIssue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.bytechef.component.ComponentHandler;
import com.bytechef.component.definition.ComponentCategory;
import com.bytechef.component.definition.ComponentDefinition;
import com.bytechef.component.github.action.GitHubCreatePullRequestAction;
import com.bytechef.component.github.action.GithubAddAssigneesToIssueAction;
import com.bytechef.component.github.action.GithubAddLabelsToIssueAction;
import com.bytechef.component.github.action.GithubCreateCommentOnIssueAction;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class GithubComponentHandler implements ComponentHandler {
GithubAddLabelsToIssueAction.ACTION_DEFINITION,
GithubCreateCommentOnIssueAction.ACTION_DEFINITION,
GithubCreateIssueAction.ACTION_DEFINITION,
GitHubCreatePullRequestAction.ACTION_DEFINITION,
GithubGetIssueAction.ACTION_DEFINITION,
GithubListIssuesAction.ACTION_DEFINITION,
GithubListRepositoryIssuesAction.ACTION_DEFINITION,
Expand All @@ -63,6 +65,7 @@ public class GithubComponentHandler implements ComponentHandler {
tool(GithubAddLabelsToIssueAction.ACTION_DEFINITION),
tool(GithubCreateCommentOnIssueAction.ACTION_DEFINITION),
tool(GithubCreateIssueAction.ACTION_DEFINITION),
tool(GitHubCreatePullRequestAction.ACTION_DEFINITION),
tool(GithubGetIssueAction.ACTION_DEFINITION),
tool(GithubListIssuesAction.ACTION_DEFINITION),
tool(GithubListRepositoryIssuesAction.ACTION_DEFINITION),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
* Copyright 2025 ByteChef
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bytechef.component.github.action;

import static com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
import static com.bytechef.component.definition.ComponentDsl.action;
import static com.bytechef.component.definition.ComponentDsl.array;
import static com.bytechef.component.definition.ComponentDsl.bool;
import static com.bytechef.component.definition.ComponentDsl.integer;
import static com.bytechef.component.definition.ComponentDsl.object;
import static com.bytechef.component.definition.ComponentDsl.outputSchema;
import static com.bytechef.component.definition.ComponentDsl.string;
import static com.bytechef.component.definition.Context.Http.responseType;
import static com.bytechef.component.github.constant.GithubConstants.BASE;
import static com.bytechef.component.github.constant.GithubConstants.BODY;
import static com.bytechef.component.github.constant.GithubConstants.DRAFT;
import static com.bytechef.component.github.constant.GithubConstants.HEAD;
import static com.bytechef.component.github.constant.GithubConstants.HEAD_REPO;
import static com.bytechef.component.github.constant.GithubConstants.ID;
import static com.bytechef.component.github.constant.GithubConstants.ISSUE;
import static com.bytechef.component.github.constant.GithubConstants.NAME;
import static com.bytechef.component.github.constant.GithubConstants.OWNER;
import static com.bytechef.component.github.constant.GithubConstants.OWNER_PROPERTY;
import static com.bytechef.component.github.constant.GithubConstants.REPOSITORY;
import static com.bytechef.component.github.constant.GithubConstants.TITLE;

import com.bytechef.component.definition.Context;
import com.bytechef.component.definition.Context.Http;
import com.bytechef.component.definition.Parameters;
import com.bytechef.component.definition.Property.ControlType;
import com.bytechef.component.definition.TypeReference;
import java.util.Map;

/**
* @author Anas Elgarhy (@0x61nas)
* @author Monika Kušter
*/
public class GitHubCreatePullRequestAction {

public static final ModifiableActionDefinition ACTION_DEFINITION = action("createPullRequest")
.title("Create Pull Request")
.description("Creates a new pull request.")
.properties(
OWNER_PROPERTY,
string(REPOSITORY)
.label("Repository")
.description("Repository where new pull request will be created.")
.required(true),
string(TITLE)
.label("Title")
.description("Title of the new pull request.")
.maxLength(100)
.required(false),
string(BODY)
.label("Body")
.description("The contents of the pull request.")
.controlType(ControlType.TEXT_AREA)
.required(false),
string(HEAD)
.label("Head")
.description(
"The name of the branch where your changes are implemented. For cross-repository pull requests " +
"in the same network, namespace head with a user like this: username:branch.")
.required(true),
string(HEAD_REPO)
.label("Head Repo")
.description(
"The name of the repository where the changes in the pull request were made. This field is " +
"required for cross-repository pull requests if both repositories are owned by the same " +
"organization.")
.required(false),
string(BASE)
.label("Base")
.description(
"The name of the branch you want the changes pulled into. This should be an existing branch " +
"on the current repository. You cannot submit a pull request to one repository that " +
"requests a merge to a base of another repository.")
.required(true),
integer(ISSUE)
.label("Issue")
.description(
"An issue in the repository to convert to a pull request. The issue title, body, " +
"and comments will become the title, body, and comments on the new pull request. " +
"Required unless title is specified.")
.required(false),
bool(DRAFT)
.label("Draft")
.description("Indicates whether the pull request is a draft.")
.defaultValue(false)
.required(true))
.output(
outputSchema(
object()
.properties(
string("url")
.description("The URL of the created pull request."),
integer(ID)
.description("ID of the created pull request."),
string("node_id"),
string("html_url"),
string("diff_url"),
string("patch_url"),
string("issue_url"),
string("commits_url"),
string("review_comment_url"),
string("comments_url"),
string("statuses_url"),
integer("number")
.description("Number uniquely identifying the pull request within its repository."),
string("state")
.description("The state of the pull request. Either open or closed."),
bool("locked")
.description(""),
string("title")
.description("The title of the pull request."),
object("user")
.description("A GitHub user.")
.properties(
string("login")
.description("The username of the assignee."),
string(ID)
.description("ID of the assignee."),
string("html_url")
.description("The URL to the assignee's profile page."),
string("type")
.description("The type of user, e.g., User or Organization.")),
string("body")
.description("The contents of the pull request."),
array("labels")
.items(
object()
.properties(
string(ID)
.description("ID of the label."),
string(NAME)
.description("Name of the label"),
string("description")
.description("A brief description of the label's purpose."))),
integer("comments")
.description("The number of comments on the pull request."),
integer("review_comments")
.description("The number of comments for review on the pull request."),
bool("maintainer_can_modify")
.description("Indicates whether maintainers can modify the pull request."),
integer("commits")
.description("The number of commits in the pull request."),
integer("additions")
.description("The number of additions in the pull request."),
integer("deletions")
.description("The number of deletions in the pull request."),
integer("changed_files")
.description("The number of changed files in the pull request."))))
.perform(GitHubCreatePullRequestAction::perform);

private GitHubCreatePullRequestAction() {
}

public static Map<String, Object> perform(
Parameters inputParameters, Parameters connectionParameters, Context context) {

return context
.http(http -> http.post(
"/repos/%s/%s/pulls".formatted(
inputParameters.getRequiredString(OWNER), inputParameters.getRequiredString(REPOSITORY))))
.body(
Http.Body.of(
TITLE, inputParameters.getString(TITLE),
HEAD, inputParameters.getRequiredString(HEAD),
HEAD_REPO, inputParameters.getString(HEAD_REPO),
BASE, inputParameters.getRequiredString(BASE),
BODY, inputParameters.getString(BODY),
DRAFT, inputParameters.getBoolean(DRAFT),
ISSUE, inputParameters.getInteger(ISSUE)))
.configuration(responseType(Http.ResponseType.JSON))
.execute()
.getBody(new TypeReference<>() {});
}
}
Loading