from teamscale_client import TeamscaleClient
from teamscale_client.constants import Enablement
from teamscale_client.data import Finding, FileFindings, FindingDescription

TEAMSCALE_URL = "http://localhost:8080"

USERNAME = "******"
ACCESS_TOKEN = "ide-access-token"

PROJECT_ID = "test"

if __name__ == '__main__':
    client = TeamscaleClient(TEAMSCALE_URL, USERNAME, ACCESS_TOKEN, PROJECT_ID)

    # Add a new group that will contain findings
    response = client.add_findings_group("Group 1", "externals-.*")
    print("Request result: %s" % (response.text, ))

    # Make Teamscale aware of a new findings type, which mappes to the previously
    # created group
    descriptions = [
        FindingDescription("externals-1", "A test finding description",
                           Enablement.RED),
        FindingDescription("externals-2", "Another finding description",
                           Enablement.YELLOW, "externals-2")
    ]
    response = client.add_finding_descriptions(descriptions)
    print("Request result: %s" % (response.text, ))

    # A manual step to add the new groups to existing analysis profiles has to be done.
    if sys.version_info[0] == 2:
from teamscale_client.constants import Enablement
from teamscale_client.data import Finding, FileFindings, FindingDescription


TEAMSCALE_URL = "http://localhost:8080"

USERNAME = "******"
PASSWORD = "******"

PROJECT_NAME = "test"

if __name__ == "__main__":
    client = TeamscaleClient(TEAMSCALE_URL, USERNAME, PASSWORD, PROJECT_NAME)

    # Add a new group that will contain findings
    response = client.add_findings_group("Group 1", "externals-.*")
    print("Request result: %s" % (response.text,))

    # Make Teamscale aware of a new findings type, which mappes to the previously
    # created group
    descriptions = [FindingDescription("externals-1", "A test finding description", Enablement.RED)]
    response = client.add_finding_descriptions(descriptions)
    print("Request result: %s" % (response.text,))

    # A manual step to add the new groups to existing analysis profiles has to be done.
    if sys.version_info[0] == 2:
        raw_input(
            "Please create the project or update the analysis profile used by the project to contain the new groups. Then Press ENTER to continue."
        )
    else:
        input(