ServiceNow-AI/gitlab-tasks huggingface dataset:
Task: gitlab.update-repo
Goal: Update the byteblaze/gimmiethat.space project site's title to "Title Wanted"
Task configuration:
namespace: byteblaze
project_name: gimmiethat.space
title: Title Wanted

Validation code:
import base64
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:

    if not messages:
        raise ValueError("Messages cannot be empty")

    if "namespace" not in config or "project_name" not in config or "title" not in config:
        raise ValueError("Target must contain 'namespace', 'project_name' and 'title'")

    project_id = quote(
        f"{config['namespace']}/{config['project_name']}", safe=""
    ).replace(".", "%2E")

    encoded_file_path = quote("index.html", safe="").replace(".", "%2E")

    url = (
        os.getenv("GITLAB_BASE_URL", "").rstrip("/")
        + "/api/v4/projects/"
        + project_id
        + "/repository/files/"
        + encoded_file_path
        + "?ref=main"
    )
    response = requests.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
    if response.status_code != 200:
        return 0
    result = response.json()

    file_content = base64.b64decode(result["content"]).decode("utf-8")

    if "<title>" + config["title"] + "</title>" in file_content:
        return 1

    return 0
Task: gitlab.update-repo
Goal: Update the byteblaze/gimmiethat.space project site's title to "Hello"
Task configuration:
namespace: byteblaze
project_name: gimmiethat.space
title: Hello

Validation code:
import base64
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:

    if not messages:
        raise ValueError("Messages cannot be empty")

    if "namespace" not in config or "project_name" not in config or "title" not in config:
        raise ValueError("Target must contain 'namespace', 'project_name' and 'title'")

    project_id = quote(
        f"{config['namespace']}/{config['project_name']}", safe=""
    ).replace(".", "%2E")

    encoded_file_path = quote("index.html", safe="").replace(".", "%2E")

    url = (
        os.getenv("GITLAB_BASE_URL", "").rstrip("/")
        + "/api/v4/projects/"
        + project_id
        + "/repository/files/"
        + encoded_file_path
        + "?ref=main"
    )
    response = requests.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
    if response.status_code != 200:
        return 0
    result = response.json()

    file_content = base64.b64decode(result["content"]).decode("utf-8")

    if "<title>" + config["title"] + "</title>" in file_content:
        return 1

    return 0
Task: gitlab.update-status
Goal: Set my gitlab status as Busy.
Task configuration:
status: Busy

Validation code:
from typing import Any, Dict, List

import requests
import json
import os

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

    if not messages:
        raise ValueError("Messages must not be empty")

    # Check whether we have the necessary information to validate
    # TODO: add relevant config parameters needed to solve the task (mandatory fields only)
    if not "status" in config:
        raise ValueError("Target must contain 'status'")

    # Build the url
    # status is always "my" status, so no need to define status by user id. For user id, change to `/api/v4/users/:id_or_username/status`
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/user/status"

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

    # special case: if status is "busy", we can rely on availability to return reward
    if config["status"].lower().strip() == "busy" and result["availability"] == "busy":
        return 1

    # otherwise, we check the message
    current_status_message = result.get("message")
    if not current_status_message:
        return 0
    if config["status"].lower().strip() == current_status_message.lower().strip():
        return 1

    return 0
Task: gitlab.update-status
Goal: Set my gitlab status as Enjoying life.
Task configuration:
status: Enjoying life

Validation code:
from typing import Any, Dict, List

import requests
import json
import os

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

    if not messages:
        raise ValueError("Messages must not be empty")

    # Check whether we have the necessary information to validate
    # TODO: add relevant config parameters needed to solve the task (mandatory fields only)
    if not "status" in config:
        raise ValueError("Target must contain 'status'")

    # Build the url
    # status is always "my" status, so no need to define status by user id. For user id, change to `/api/v4/users/:id_or_username/status`
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/user/status"

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

    # special case: if status is "busy", we can rely on availability to return reward
    if config["status"].lower().strip() == "busy" and result["availability"] == "busy":
        return 1

    # otherwise, we check the message
    current_status_message = result.get("message")
    if not current_status_message:
        return 0
    if config["status"].lower().strip() == current_status_message.lower().strip():
        return 1

    return 0
Task: gitlab.update-status
Goal: Set my gitlab status as Playing Badminton.
Task configuration:
status: Playing Badminton

Validation code:
from typing import Any, Dict, List

import requests
import json
import os

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

    if not messages:
        raise ValueError("Messages must not be empty")

    # Check whether we have the necessary information to validate
    # TODO: add relevant config parameters needed to solve the task (mandatory fields only)
    if not "status" in config:
        raise ValueError("Target must contain 'status'")

    # Build the url
    # status is always "my" status, so no need to define status by user id. For user id, change to `/api/v4/users/:id_or_username/status`
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/user/status"

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

    # special case: if status is "busy", we can rely on availability to return reward
    if config["status"].lower().strip() == "busy" and result["availability"] == "busy":
        return 1

    # otherwise, we check the message
    current_status_message = result.get("message")
    if not current_status_message:
        return 0
    if config["status"].lower().strip() == current_status_message.lower().strip():
        return 1

    return 0
Task: gitlab.update-status
Goal: Set my gitlab status as Resting due to leg injury.
Task configuration:
status: Resting due to leg injury

Validation code:
from typing import Any, Dict, List

import requests
import json
import os

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

    if not messages:
        raise ValueError("Messages must not be empty")

    # Check whether we have the necessary information to validate
    # TODO: add relevant config parameters needed to solve the task (mandatory fields only)
    if not "status" in config:
        raise ValueError("Target must contain 'status'")

    # Build the url
    # status is always "my" status, so no need to define status by user id. For user id, change to `/api/v4/users/:id_or_username/status`
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/user/status"

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

    # special case: if status is "busy", we can rely on availability to return reward
    if config["status"].lower().strip() == "busy" and result["availability"] == "busy":
        return 1

    # otherwise, we check the message
    current_status_message = result.get("message")
    if not current_status_message:
        return 0
    if config["status"].lower().strip() == current_status_message.lower().strip():
        return 1

    return 0
Task: gitlab.update-status
Goal: Set my gitlab status as Out of Office.
Task configuration:
status: Out of Office

Validation code:
from typing import Any, Dict, List

import requests
import json
import os

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

    if not messages:
        raise ValueError("Messages must not be empty")

    # Check whether we have the necessary information to validate
    # TODO: add relevant config parameters needed to solve the task (mandatory fields only)
    if not "status" in config:
        raise ValueError("Target must contain 'status'")

    # Build the url
    # status is always "my" status, so no need to define status by user id. For user id, change to `/api/v4/users/:id_or_username/status`
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/user/status"

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

    # special case: if status is "busy", we can rely on availability to return reward
    if config["status"].lower().strip() == "busy" and result["availability"] == "busy":
        return 1

    # otherwise, we check the message
    current_status_message = result.get("message")
    if not current_status_message:
        return 0
    if config["status"].lower().strip() == current_status_message.lower().strip():
        return 1

    return 0