<commit_before>package org.shipkit.internal.gradle.versionupgrade;

import org.gradle.api.DefaultTask;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.tasks.TaskAction;
import org.shipkit.gradle.ReleaseConfiguration;
import org.shipkit.internal.util.ExposedForTesting;
import org.shipkit.internal.util.GitHubApi;

import java.io.IOException;

/**
 * Creates a pull request in {@link CreatePullRequestTask#repositoryUrl} of title {@link CreatePullRequestTask#title}
 * between {@link CreatePullRequestTask#baseBranch} and {@link CreatePullRequestTask#headBranch}
 */
public class CreatePullRequestTask extends DefaultTask{

    private static final Logger LOG = Logging.getLogger(CreatePullRequestTask.class);

    private String repositoryUrl;
    private String gitHubApiUrl;
    private String authToken;
    private String title;
    private String headBranch;
    private String baseBranch;

    private GitHubApi gitHubApi;

    @TaskAction
    public void createPullRequest() throws IOException {
        if(gitHubApi == null) {
            gitHubApi = new GitHubApi(gitHubApiUrl, authToken);
        }

        LOG.lifecycle("  Creating a pull request of title '{}' in repository '{}' between base = '{}' and head = '{}'.",
            title, repositoryUrl, baseBranch, headBranch);

        String body = "{" +
            "  \"title\": \"" + title + "\"," +
            "  \"body\": \"Please pull this in!\"," +
            "  \"head\": \"" + headBranch + "\"," +
            "  \"base\": \"" + baseBranch + "\"" +
            "}";

        try {
            gitHubApi.post("/repos/" + repositoryUrl + "/pulls", body);
        } catch(IOException e){
            LOG.error("  Creating a pull request failed.\n  {}", e.getMessage());
        }
    }


    /**
     * See {@link ReleaseConfiguration.GitHub#getRepository()}
     */
    public String getRepositoryUrl() {
        return repositoryUrl;
    }

    /**
     * See {@link ReleaseConfiguration.GitHub#getRepository()}
     */
    public void setRepositoryUrl(String repositoryUrl) {
        this.repositoryUrl = repositoryUrl;
    }

    /**
     * See {@link ReleaseConfiguration.GitHub#getApiUrl()}
     */
    public String getGitHubApiUrl() {
        return gitHubApiUrl;
    }

    /**
     * See {@link ReleaseConfiguration.GitHub#getApiUrl()}
     */
    public void setGitHubApiUrl(String gitHubApiUrl) {
        this.gitHubApiUrl = gitHubApiUrl;<commit_msg>Removed redundant try-catch in GitCheckoutTask #302<commit_after>package org.shipkit.internal.gradle.versionupgrade;

import org.gradle.api.DefaultTask;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.tasks.TaskAction;
import org.shipkit.gradle.ReleaseConfiguration;
import org.shipkit.internal.util.ExposedForTesting;
import org.shipkit.internal.util.GitHubApi;

import java.io.IOException;

/**
 * Creates a pull request in {@link CreatePullRequestTask#repositoryUrl} of title {@link CreatePullRequestTask#title}
 * between {@link CreatePullRequestTask#baseBranch} and {@link CreatePullRequestTask#headBranch}
 */
public class CreatePullRequestTask extends DefaultTask{

    private static final Logger LOG = Logging.getLogger(CreatePullRequestTask.class);

    private String repositoryUrl;
    private String gitHubApiUrl;
    private String authToken;
    private String title;
    private String headBranch;
    private String baseBranch;

    private GitHubApi gitHubApi;

    @TaskAction
    public void createPullRequest() throws IOException {
        if(gitHubApi == null) {
            gitHubApi = new GitHubApi(gitHubApiUrl, authToken);
        }

        LOG.lifecycle("  Creating a pull request of title '{}' in repository '{}' between base = '{}' and head = '{}'.",
            title, repositoryUrl, baseBranch, headBranch);

        String body = "{" +
            "  \"title\": \"" + title + "\"," +
            "  \"body\": \"Please pull this in!\"," +
            "  \"head\": \"" + headBranch + "\"," +
            "  \"base\": \"" + baseBranch + "\"" +
            "}";

        gitHubApi.post("/repos/" + repositoryUrl + "/pulls", body);
    }


    /**
     * See {@link ReleaseConfiguration.GitHub#getRepository()}
     */
    public String getRepositoryUrl() {
        return repositoryUrl;
    }

    /**
     * See {@link ReleaseConfiguration.GitHub#getRepository()}
     */
    public void setRepositoryUrl(String repositoryUrl) {
        this.repositoryUrl = repositoryUrl;
    }

    /**
     * See {@link ReleaseConfiguration.GitHub#getApiUrl()}
     */
    public String getGitHubApiUrl() {
        return gitHubApiUrl;
    }

    /**
     * See {@link ReleaseConfiguration.GitHub#getApiUrl()}
     */
    public void setGitHubApiUrl(String gitHubApiUrl) {
        this.gitHubApiUrl = gitHubApiUrl;
{'fraction_non_alphanumeric': 0.12289354706124127, 'fraction_numerical': 0.0006165228113440197, 'mean_word_length': 2.9092369477911646, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6206750', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1352, 'n_words': 308}