package org.shipkit.gradle.notes;

import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.shipkit.gradle.configuration.ShipkitConfiguration;
import org.shipkit.internal.gradle.notes.tasks.FetchReleaseNotes;

import java.io.File;
import java.util.Collection;
import java.util.Collections;

/**
 * Fetches release notes data information from Git and GitHub
 * and serializes it to file specified with {@link #outputFile}.
 */
public class FetchReleaseNotesTask extends DefaultTask {

    @Input @Optional private String previousVersion;
    @Input private String version = getProject().getVersion().toString();
    @Input private String gitHubApiUrl;
    @Input private String gitHubReadOnlyAuthToken;
    @Input private String gitHubRepository;
    @Input private String tagPrefix;
    @Input private boolean onlyPullRequests;
    @Input private File gitWorkDir = getProject().getRootDir();
    @Input private Collection<String> gitHubLabels = Collections.emptyList();
    @Input private Collection<String> ignoreCommitsContaining;
    @OutputFile private File outputFile;

    @TaskAction
    public void fetchReleaseNotes() {
        new FetchReleaseNotes().fetchReleaseNotes(this);
    }

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

    /**
     * See {@link #getGitHubApiUrl()}
     */
    public void setGitHubApiUrl(String gitHubApiUrl) {
        this.gitHubApiUrl = gitHubApiUrl;
    }

    /**
     * See {@link ShipkitConfiguration.GitHub#getReadOnlyAuthToken()}
     */
    public String getGitHubReadOnlyAuthToken() {
        return gitHubReadOnlyAuthToken;
    }

    /**
     * See {@link #getGitHubReadOnlyAuthToken()}
     */
    public void setGitHubReadOnlyAuthToken(String readOnlyToken) {
        this.gitHubReadOnlyAuthToken = readOnlyToken;
    }

    /**
     * See {@link ShipkitConfiguration.GitHub#getRepository()}
     */
    public String getGitHubRepository() {
        return gitHubRepository;
    }

    /**
     * See {@link #getGitHubRepository()}
     */
    public void setGitHubRepository(String gitHubRepository) {
        this.gitHubRepository = gitHubRepository;
    }

    /**
     * Previous released version we generate the release notes from.
     * See {@link ShipkitConfiguration#getPreviousReleaseVersion()}
     */
    public String getPreviousVersion() {
        return previousVersion;
    }

    /**
     * See {@link #getPreviousVersion()}
     */
    public void setPreviousVersion(String previousVersion) {
        this.previousVersion = previousVersion;
    }

    /**
     * The file release notes data will be saved to
     */
    public File getOutputFile() {
        return outputFile;
    }

    /**
     * See {@link #getOutputFile()}
     */
    public void setOutputFile(File outputFile) {
        this.outputFile = outputFile;
    }

    /**
     * Version we generate release notes data for
     */
    public String getVersion() {
        return version;
    }

    /**
     * See {@link #getVersion()}
     */
    public void setVersion(String version) {
        this.version = version;
    }

    /**
     * Whether to include only pull requests in the release notes data
     */
    public boolean isOnlyPullRequests() {
        return onlyPullRequests;
    }

    /**
     * See {@link #isOnlyPullRequests()}
     */
    public void setOnlyPullRequests(boolean onlyPullRequests) {
        this.onlyPullRequests = onlyPullRequests;
    }

    /**
     * See {@link ShipkitConfiguration.Git#getTagPrefix()}
     */
    public String getTagPrefix() {
        return tagPrefix;
    }

    /**
     * See {@link #getTagPrefix()}
     */
    public void setTagPrefix(String tagPrefix) {
        this.tagPrefix = tagPrefix;
    }

    /**
     * Work directory where git operations will be invoked (like 'git log', etc.)
     */
    public File getGitWorkDir() {
        return gitWorkDir;
    }

    /**
     * See {@link #getGitWorkDir()}
     */
    public void setGitWorkDir(File gitWorkDir) {
        this.gitWorkDir = gitWorkDir;
    }

    /**
     * GitHub labels to include when querying GitHub issues API.
     * If empty, then all labels will be included.
     * If labels are configured, only tickets with those labels will be included in the release notes.
     */
    public Collection<String> getGitHubLabels() {
        return gitHubLabels;
    }

    /**
     * See {@link #getGitHubLabels()}
     */
    public void setGitHubLabels(Collection<String> gitHubLabels) {
        this.gitHubLabels = gitHubLabels;
    }

    /**
     * See {@link ShipkitConfiguration.ReleaseNotes#getIgnoreCommitsContaining()}
     */
    public Collection<String> getIgnoreCommitsContaining() {
        return ignoreCommitsContaining;
    }

    /**
     * See {@link #getIgnoreCommitsContaining()}
     */
    public void setIgnoreCommitsContaining(Collection<String> ignoreCommitsContaining) {
        this.ignoreCommitsContaining = ignoreCommitsContaining;
    }
}

@@ -220,70 +220,8 @@
 on;%0A
-import org.shipkit.gradle.configuration.ShipkitConfiguration;%0A
 impo
@@ -278,24 +278,24 @@
 leaseNotes;%0A
+
 %0Aimport java
@@ -1284,32 +1284,65 @@
    * See %7B@link 
+org.shipkit.gradle.configuration.
 ShipkitConfigura
@@ -1621,32 +1621,65 @@
    * See %7B@link 
+org.shipkit.gradle.configuration.
 ShipkitConfigura
@@ -2029,32 +2029,65 @@
    * See %7B@link 
+org.shipkit.gradle.configuration.
 ShipkitConfigura
@@ -2470,32 +2470,65 @@
    * See %7B@link 
+org.shipkit.gradle.configuration.
 ShipkitConfigura
@@ -3732,32 +3732,65 @@
    * See %7B@link 
+org.shipkit.gradle.configuration.
 ShipkitConfigura
@@ -4836,32 +4836,32 @@
 %0A    %7D%0A%0A    /**%0A
-
      * See %7B@lin
@@ -4862,16 +4862,49 @@
  %7B@link 
+org.shipkit.gradle.configuration.
 ShipkitC

Fix javadoc in FetchReleaseNotesTask