ServiceNow-AI/gitlab-tasks huggingface dataset:
Task: gitlab.create-group
Goal: create a new group "n-lab" with members patou, egpast, westurner, jontutcher
Task configuration:
group_members: patou, egpast, westurner, jontutcher
group_name: n-lab

Validation code:
from typing import Any, Dict, List
from urllib.parse import quote

import requests
import json
import os

def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:

    # Check whether we have the necessary information to validate
    if not "group_name" in config or not "group_members" in config:
        raise ValueError("Target must contain 'group_name' and 'group_members'")

    # check whether we have messages
    if not messages:
        raise ValueError("Messages are empty")

    group_id = quote(f"{config['group_name']}", safe="")

    # TODO: maybe paginate?
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/groups/" + group_id + "/members"

    response = requests.request(
        method="GET",
        url=url,
        headers={
            "Content-Type": "application/json",
            "Accept": "application/json",
            **json.loads(os.getenv("GITLAB_EXTRA_HTTP_HEADERS", "{}")),
        },
    )
    if response.status_code == 404:
        return 0
    response.raise_for_status()

    response_members = [elem["username"].lower().strip() for elem in response.json()]
    response_members += [elem["name"].lower().strip() for elem in response.json()]
    for member in config["group_members"].split(", "):
        if member.lower().strip() not in response_members:
            return 0
    return 1
Task: gitlab.create-group
Goal: create a new group "x-lab" with members JonasVautherin, dilipchandima, dawiss1337, bmyun, DCMJY
Task configuration:
group_members: JonasVautherin, dilipchandima, dawiss1337, bmyun, DCMJY
group_name: x-lab

Validation code:
from typing import Any, Dict, List
from urllib.parse import quote

import requests
import json
import os

def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:

    # Check whether we have the necessary information to validate
    if not "group_name" in config or not "group_members" in config:
        raise ValueError("Target must contain 'group_name' and 'group_members'")

    # check whether we have messages
    if not messages:
        raise ValueError("Messages are empty")

    group_id = quote(f"{config['group_name']}", safe="")

    # TODO: maybe paginate?
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/groups/" + group_id + "/members"

    response = requests.request(
        method="GET",
        url=url,
        headers={
            "Content-Type": "application/json",
            "Accept": "application/json",
            **json.loads(os.getenv("GITLAB_EXTRA_HTTP_HEADERS", "{}")),
        },
    )
    if response.status_code == 404:
        return 0
    response.raise_for_status()

    response_members = [elem["username"].lower().strip() for elem in response.json()]
    response_members += [elem["name"].lower().strip() for elem in response.json()]
    for member in config["group_members"].split(", "):
        if member.lower().strip() not in response_members:
            return 0
    return 1
Task: gitlab.create-group
Goal: create a new group "crew" with members ASWATFZLLC, patrickhlauke, westurner, linkmatrix
Task configuration:
group_members: ASWATFZLLC, patrickhlauke, westurner, linkmatrix
group_name: crew

Validation code:
from typing import Any, Dict, List
from urllib.parse import quote

import requests
import json
import os

def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:

    # Check whether we have the necessary information to validate
    if not "group_name" in config or not "group_members" in config:
        raise ValueError("Target must contain 'group_name' and 'group_members'")

    # check whether we have messages
    if not messages:
        raise ValueError("Messages are empty")

    group_id = quote(f"{config['group_name']}", safe="")

    # TODO: maybe paginate?
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/groups/" + group_id + "/members"

    response = requests.request(
        method="GET",
        url=url,
        headers={
            "Content-Type": "application/json",
            "Accept": "application/json",
            **json.loads(os.getenv("GITLAB_EXTRA_HTTP_HEADERS", "{}")),
        },
    )
    if response.status_code == 404:
        return 0
    response.raise_for_status()

    response_members = [elem["username"].lower().strip() for elem in response.json()]
    response_members += [elem["name"].lower().strip() for elem in response.json()]
    for member in config["group_members"].split(", "):
        if member.lower().strip() not in response_members:
            return 0
    return 1
Task: gitlab.create-group
Goal: create a new group "coding_friends" with members qhduan, Agnes-U
Task configuration:
group_members: qhduan, Agnes-U
group_name: coding_friends

Validation code:
from typing import Any, Dict, List
from urllib.parse import quote

import requests
import json
import os

def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:

    # Check whether we have the necessary information to validate
    if not "group_name" in config or not "group_members" in config:
        raise ValueError("Target must contain 'group_name' and 'group_members'")

    # check whether we have messages
    if not messages:
        raise ValueError("Messages are empty")

    group_id = quote(f"{config['group_name']}", safe="")

    # TODO: maybe paginate?
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/groups/" + group_id + "/members"

    response = requests.request(
        method="GET",
        url=url,
        headers={
            "Content-Type": "application/json",
            "Accept": "application/json",
            **json.loads(os.getenv("GITLAB_EXTRA_HTTP_HEADERS", "{}")),
        },
    )
    if response.status_code == 404:
        return 0
    response.raise_for_status()

    response_members = [elem["username"].lower().strip() for elem in response.json()]
    response_members += [elem["name"].lower().strip() for elem in response.json()]
    for member in config["group_members"].split(", "):
        if member.lower().strip() not in response_members:
            return 0
    return 1
Task: gitlab.create-group
Goal: create a new group "webagent" with members pandey2000, sayakpaul, sayakpaul
Task configuration:
group_members: pandey2000, sayakpaul, sayakpaul
group_name: webagent

Validation code:
from typing import Any, Dict, List
from urllib.parse import quote

import requests
import json
import os

def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:

    # Check whether we have the necessary information to validate
    if not "group_name" in config or not "group_members" in config:
        raise ValueError("Target must contain 'group_name' and 'group_members'")

    # check whether we have messages
    if not messages:
        raise ValueError("Messages are empty")

    group_id = quote(f"{config['group_name']}", safe="")

    # TODO: maybe paginate?
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/groups/" + group_id + "/members"

    response = requests.request(
        method="GET",
        url=url,
        headers={
            "Content-Type": "application/json",
            "Accept": "application/json",
            **json.loads(os.getenv("GITLAB_EXTRA_HTTP_HEADERS", "{}")),
        },
    )
    if response.status_code == 404:
        return 0
    response.raise_for_status()

    response_members = [elem["username"].lower().strip() for elem in response.json()]
    response_members += [elem["name"].lower().strip() for elem in response.json()]
    for member in config["group_members"].split(", "):
        if member.lower().strip() not in response_members:
            return 0
    return 1
Task: gitlab.create-milestone
Goal: Create a milestone for the upcoming event of product launch starting on 1/16/2023 and ending on 1/30/2023 in repo primer/design
Task configuration:
namespace: primer
project_name: design
text_end_date: 1/30/2023
end_date: 2023-01-30
event: event of product launch
search_keywords: product launch
text_start_date: 1/16/2023
start_date: 2023-01-16

Validation code:
from typing import Any, Dict, List
from urllib.parse import quote

import requests
import json
import os

def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:
    # Check whether we have the necessary information to validate
    if (
        not "namespace" in config
        or not "project_name" in config
        or not "search_keywords" in config
    ):
        raise ValueError(
            "Target must contain 'namespace', 'project_name' and 'search_keywords'"
        )

    # check whether we have messages
    if not messages:
        raise ValueError("Messages are empty")

    project_id = quote(f"{config['namespace']}/{config['project_name']}", safe="")

    # search for milestone
    url = (
        os.getenv("GITLAB_BASE_URL", "").rstrip("/")
        + "/api/v4/projects/"
        + project_id
        + "/milestones"
        + "?search="
        + quote(config["search_keywords"], safe="")
    )

    response = requests.request(
        method="GET",
        url=url,
        headers={
            "Content-Type": "application/json",
            "Accept": "application/json",
            **json.loads(os.getenv("GITLAB_EXTRA_HTTP_HEADERS", "{}")),
        },
    )
    if response.status_code != 200:
        return 0
    result = response.json()
    if len(result) == 0:
        return 0
    result = result[0]

    if config.get("start_date"):
        if result["start_date"] != config["start_date"]:
            return 0

    if config.get("end_date"):
        if result["due_date"] != config["end_date"]:
            return 0

    return 1
Task: gitlab.create-milestone
Goal: Create a milestone for the upcoming practice of collective code review starting on 1/16/2023 and ending on in 20 days in repo primer/design
Task configuration:
namespace: primer
project_name: design
text_end_date: in 20 days
end_date: 2023-02-05
event: practice of collective code review
search_keywords: collective code review
text_start_date: 1/16/2023
start_date: 2023-01-16

Validation code:
from typing import Any, Dict, List
from urllib.parse import quote

import requests
import json
import os

def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:
    # Check whether we have the necessary information to validate
    if (
        not "namespace" in config
        or not "project_name" in config
        or not "search_keywords" in config
    ):
        raise ValueError(
            "Target must contain 'namespace', 'project_name' and 'search_keywords'"
        )

    # check whether we have messages
    if not messages:
        raise ValueError("Messages are empty")

    project_id = quote(f"{config['namespace']}/{config['project_name']}", safe="")

    # search for milestone
    url = (
        os.getenv("GITLAB_BASE_URL", "").rstrip("/")
        + "/api/v4/projects/"
        + project_id
        + "/milestones"
        + "?search="
        + quote(config["search_keywords"], safe="")
    )

    response = requests.request(
        method="GET",
        url=url,
        headers={
            "Content-Type": "application/json",
            "Accept": "application/json",
            **json.loads(os.getenv("GITLAB_EXTRA_HTTP_HEADERS", "{}")),
        },
    )
    if response.status_code != 200:
        return 0
    result = response.json()
    if len(result) == 0:
        return 0
    result = result[0]

    if config.get("start_date"):
        if result["start_date"] != config["start_date"]:
            return 0

    if config.get("end_date"):
        if result["due_date"] != config["end_date"]:
            return 0

    return 1
Task: gitlab.create-milestone
Goal: Create a milestone for the upcoming task of cleaning sensitive information starting on 2/16/2023 and ending on in 20 days in repo primer/design
Task configuration:
namespace: primer
project_name: design
text_end_date: in 20 days
end_date: 2023-03-08
event: task of cleaning sensitive information
search_keywords: clean sensitive information
text_start_date: 2/16/2023
start_date: 2023-02-16

Validation code:
from typing import Any, Dict, List
from urllib.parse import quote

import requests
import json
import os

def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:
    # Check whether we have the necessary information to validate
    if (
        not "namespace" in config
        or not "project_name" in config
        or not "search_keywords" in config
    ):
        raise ValueError(
            "Target must contain 'namespace', 'project_name' and 'search_keywords'"
        )

    # check whether we have messages
    if not messages:
        raise ValueError("Messages are empty")

    project_id = quote(f"{config['namespace']}/{config['project_name']}", safe="")

    # search for milestone
    url = (
        os.getenv("GITLAB_BASE_URL", "").rstrip("/")
        + "/api/v4/projects/"
        + project_id
        + "/milestones"
        + "?search="
        + quote(config["search_keywords"], safe="")
    )

    response = requests.request(
        method="GET",
        url=url,
        headers={
            "Content-Type": "application/json",
            "Accept": "application/json",
            **json.loads(os.getenv("GITLAB_EXTRA_HTTP_HEADERS", "{}")),
        },
    )
    if response.status_code != 200:
        return 0
    result = response.json()
    if len(result) == 0:
        return 0
    result = result[0]

    if config.get("start_date"):
        if result["start_date"] != config["start_date"]:
            return 0

    if config.get("end_date"):
        if result["due_date"] != config["end_date"]:
            return 0

    return 1
Task: gitlab.create-milestone
Goal: Create a milestone for the upcoming task of merging all branches to main starting on March 15, 2044 and ending on March 30, 2044 in repo byteblaze/dotfiles
Task configuration:
namespace: byteblaze
project_name: dotfiles
text_end_date: March 30, 2044
end_date: 2044-03-30
event: task of merging all branches to main
search_keywords: merge branch main
text_start_date: March 15, 2044
start_date: 2044-03-15

Validation code:
from typing import Any, Dict, List
from urllib.parse import quote

import requests
import json
import os

def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:
    # Check whether we have the necessary information to validate
    if (
        not "namespace" in config
        or not "project_name" in config
        or not "search_keywords" in config
    ):
        raise ValueError(
            "Target must contain 'namespace', 'project_name' and 'search_keywords'"
        )

    # check whether we have messages
    if not messages:
        raise ValueError("Messages are empty")

    project_id = quote(f"{config['namespace']}/{config['project_name']}", safe="")

    # search for milestone
    url = (
        os.getenv("GITLAB_BASE_URL", "").rstrip("/")
        + "/api/v4/projects/"
        + project_id
        + "/milestones"
        + "?search="
        + quote(config["search_keywords"], safe="")
    )

    response = requests.request(
        method="GET",
        url=url,
        headers={
            "Content-Type": "application/json",
            "Accept": "application/json",
            **json.loads(os.getenv("GITLAB_EXTRA_HTTP_HEADERS", "{}")),
        },
    )
    if response.status_code != 200:
        return 0
    result = response.json()
    if len(result) == 0:
        return 0
    result = result[0]

    if config.get("start_date"):
        if result["start_date"] != config["start_date"]:
            return 0

    if config.get("end_date"):
        if result["due_date"] != config["end_date"]:
            return 0

    return 1
Task: gitlab.create-milestone
Goal: Create a milestone for the upcoming task of adding a new branch for zsh comprehensive support starting on 5/1/2044 and ending on in 20 days in repo byteblaze/dotfiles
Task configuration:
namespace: byteblaze
project_name: dotfiles
text_end_date: in 20 days
end_date: 2044-05-21
event: task of adding a new branch for zsh comprehensive support
search_keywords: branch zsh support
text_start_date: 5/1/2044
start_date: 2044-05-01

Validation code:
from typing import Any, Dict, List
from urllib.parse import quote

import requests
import json
import os

def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:
    # Check whether we have the necessary information to validate
    if (
        not "namespace" in config
        or not "project_name" in config
        or not "search_keywords" in config
    ):
        raise ValueError(
            "Target must contain 'namespace', 'project_name' and 'search_keywords'"
        )

    # check whether we have messages
    if not messages:
        raise ValueError("Messages are empty")

    project_id = quote(f"{config['namespace']}/{config['project_name']}", safe="")

    # search for milestone
    url = (
        os.getenv("GITLAB_BASE_URL", "").rstrip("/")
        + "/api/v4/projects/"
        + project_id
        + "/milestones"
        + "?search="
        + quote(config["search_keywords"], safe="")
    )

    response = requests.request(
        method="GET",
        url=url,
        headers={
            "Content-Type": "application/json",
            "Accept": "application/json",
            **json.loads(os.getenv("GITLAB_EXTRA_HTTP_HEADERS", "{}")),
        },
    )
    if response.status_code != 200:
        return 0
    result = response.json()
    if len(result) == 0:
        return 0
    result = result[0]

    if config.get("start_date"):
        if result["start_date"] != config["start_date"]:
            return 0

    if config.get("end_date"):
        if result["due_date"] != config["end_date"]:
            return 0

    return 1
Task: gitlab.create-pr
Goal: Submit a request to merge dev branch into main branch for repo facebook/buck, assign Meta as the reviewer
Task configuration:
namespace: facebook
project_name: buck
reviewer: Meta
source_branch: dev
target_branch: main

Validation code:
from typing import Any, Dict, List
from urllib.parse import quote

import requests
import json
import os

def _get_headers():
    return {
        "Content-Type": "application/json",
        "Accept": "application/json",
        **json.loads(os.getenv("GITLAB_EXTRA_HTTP_HEADERS", "{}")),
    }

def _get_current_user():
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/user"
    response = requests.get(url=url, headers=_get_headers())
    if response.status_code == 200:
        return response.json()
    return None

def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:

    # Check whether we have the necessary information to validate
    if (
        not "namespace" in config
        or not "project_name" in config
        or not "source_branch" in config
        or not "target_branch" in config
    ):
        raise ValueError(
            "Target must contain 'namespace', 'project_name', 'source_branch' and 'target_branch'"
        )

    # check whether we have messages
    if not messages:
        raise ValueError("Messages are empty")

    project_id = quote(f"{config['namespace']}/{config['project_name']}", safe="")

    url = (
        os.getenv("GITLAB_BASE_URL", "").rstrip("/")
        + "/api/v4/projects/"
        + project_id
        + "/merge_requests"
        + "?source_branch="
        + config["source_branch"]
        + "&target_branch="
        + config["target_branch"]
    )

    response = requests.get(url=url, headers=_get_headers())
    if response.status_code != 200:
        return 0
    result = response.json()

    if len(result) == 0:
        return 0
    result = result[0]

    if "reviewer" in config:
        reviewer_value = config["reviewer"].lower().strip()

        # Handle "myself" as reviewer
        if reviewer_value == "myself":
            current_user = _get_current_user()
            if current_user is None:
                return 0
            for elem in result["reviewers"]:
                if (current_user["username"].lower() in elem["username"].lower()
                    or current_user["name"].lower() in elem["name"].lower()):
                    return 1
            return 0
        else:
            for elem in result["reviewers"]:
                if (reviewer_value in elem["name"].lower()
                    or reviewer_value in elem["username"].lower()):
                    return 1
            return 0

    # default: do not check if we need reviewers
    return 1
Task: gitlab.create-pr
Goal: Submit a merge request in the primer/design repo for dialog-component branch to be merged into bump-doctocat branch, assign primer as the reviewer
Task configuration:
namespace: primer
project_name: design
source_branch: dialog-component
target_branch: bump-doctocat
reviewer: primer

Validation code:
from typing import Any, Dict, List
from urllib.parse import quote

import requests
import json
import os

def _get_headers():
    return {
        "Content-Type": "application/json",
        "Accept": "application/json",
        **json.loads(os.getenv("GITLAB_EXTRA_HTTP_HEADERS", "{}")),
    }

def _get_current_user():
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/user"
    response = requests.get(url=url, headers=_get_headers())
    if response.status_code == 200:
        return response.json()
    return None

def validate(messages: List[Dict[str, str]], config: Dict[str, Any]) -> int:

    # Check whether we have the necessary information to validate
    if (
        not "namespace" in config
        or not "project_name" in config
        or not "source_branch" in config
        or not "target_branch" in config
    ):
        raise ValueError(
            "Target must contain 'namespace', 'project_name', 'source_branch' and 'target_branch'"
        )

    # check whether we have messages
    if not messages:
        raise ValueError("Messages are empty")

    project_id = quote(f"{config['namespace']}/{config['project_name']}", safe="")

    url = (
        os.getenv("GITLAB_BASE_URL", "").rstrip("/")
        + "/api/v4/projects/"
        + project_id
        + "/merge_requests"
        + "?source_branch="
        + config["source_branch"]
        + "&target_branch="
        + config["target_branch"]
    )

    response = requests.get(url=url, headers=_get_headers())
    if response.status_code != 200:
        return 0
    result = response.json()

    if len(result) == 0:
        return 0
    result = result[0]

    if "reviewer" in config:
        reviewer_value = config["reviewer"].lower().strip()

        # Handle "myself" as reviewer
        if reviewer_value == "myself":
            current_user = _get_current_user()
            if current_user is None:
                return 0
            for elem in result["reviewers"]:
                if (current_user["username"].lower() in elem["username"].lower()
                    or current_user["name"].lower() in elem["name"].lower()):
                    return 1
            return 0
        else:
            for elem in result["reviewers"]:
                if (reviewer_value in elem["name"].lower()
                    or reviewer_value in elem["username"].lower()):
                    return 1
            return 0

    # default: do not check if we need reviewers
    return 1