ServiceNow-AI/gitlab-tasks huggingface dataset:
Task: gitlab.star-repo
Goal: Star the top one most stared repos in Gitlab
Task configuration:
number: one

Validation code:
from typing import Any, Dict, List

import requests
import json
import os

MOST_STARRED_REPOS = [
    "AndroidSlidingUpPanel",
    "create-react-app",
    "ffmpeg-python",
    "PHP_XLSXWriter",
    "AndroidAsync",
    "Pytorch-GAN",
    "administrate",
    "keycloak",
]

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

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

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

    # map number (one, two, three, etc.) to int
    number = config["number"]
    if number == "one":
        number = 1
    elif number == "two":
        number = 2
    elif number == "three":
        number = 3
    elif number == "four":
        number = 4
    elif number == "five":
        number = 5
    elif number == "six":
        number = 6
    elif number == "seven":
        number = 7
    elif number == "eight":
        number = 8
    elif number == "nine":
        number = 9
    elif number == "ten":
        number = 10
    else:
        # TODO: better way of scaling this to *arbitrary* number?
        raise ValueError("Invalid number")

    # Build the url
    # TODO: maybe support all users?
    # TODO: maybe support pagination? or sort by stars to only get the most recent repos
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/projects?starred=true"

    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()

    # TODO: validate fields you need here
    repo_names = [repo["name"] for repo in result]
    for repo_name in MOST_STARRED_REPOS[:number]:
        if repo_name not in repo_names:
            return 0
    return 1
Task: gitlab.update-license
Goal: Make the LICENSE of Administrator/sample-gitlab to MIT license.
Task configuration:
display_namespace: Administrator
namespace: root
project_name: sample-gitlab
license_type: MIT

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:

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

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

    expected_license = config.get("license") or config.get("license_type")

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

    # Build the url
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/projects/" + project_id + "?license=true"

    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()

    # Check if the license matches (flexible matching)
    actual_license_key = result["license"]["key"].lower().strip()
    expected = expected_license.lower().strip()

    # Direct match
    if actual_license_key == expected:
        return 1

    # Flexible matching: e.g., "MIT" matches "mit", "Apache" matches "apache-2.0", "GPL" matches "gpl-2.0" or "gpl-3.0"
    if expected in actual_license_key or actual_license_key in expected:
        return 1

    return 0
Task: gitlab.update-license
Goal: Make the LICENSE of Byte Blaze/dotfiles to MIT license.
Task configuration:
display_namespace: Byte Blaze
namespace: byteblaze
project_name: dotfiles
license_type: MIT

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:

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

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

    expected_license = config.get("license") or config.get("license_type")

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

    # Build the url
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/projects/" + project_id + "?license=true"

    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()

    # Check if the license matches (flexible matching)
    actual_license_key = result["license"]["key"].lower().strip()
    expected = expected_license.lower().strip()

    # Direct match
    if actual_license_key == expected:
        return 1

    # Flexible matching: e.g., "MIT" matches "mit", "Apache" matches "apache-2.0", "GPL" matches "gpl-2.0" or "gpl-3.0"
    if expected in actual_license_key or actual_license_key in expected:
        return 1

    return 0
Task: gitlab.update-license
Goal: Make the LICENSE of Learn Anything/learn-anything to MIT license.
Task configuration:
display_namespace: Learn Anything
namespace: learn-anything
project_name: learn-anything
license_type: MIT

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:

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

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

    expected_license = config.get("license") or config.get("license_type")

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

    # Build the url
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/projects/" + project_id + "?license=true"

    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()

    # Check if the license matches (flexible matching)
    actual_license_key = result["license"]["key"].lower().strip()
    expected = expected_license.lower().strip()

    # Direct match
    if actual_license_key == expected:
        return 1

    # Flexible matching: e.g., "MIT" matches "mit", "Apache" matches "apache-2.0", "GPL" matches "gpl-2.0" or "gpl-3.0"
    if expected in actual_license_key or actual_license_key in expected:
        return 1

    return 0
Task: gitlab.update-license
Goal: Make the LICENSE of byteblaze/accessible-html-content-patterns to Apache License
Task configuration:
namespace: byteblaze
project_name: accessible-html-content-patterns
license_type: Apache

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:

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

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

    expected_license = config.get("license") or config.get("license_type")

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

    # Build the url
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/projects/" + project_id + "?license=true"

    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()

    # Check if the license matches (flexible matching)
    actual_license_key = result["license"]["key"].lower().strip()
    expected = expected_license.lower().strip()

    # Direct match
    if actual_license_key == expected:
        return 1

    # Flexible matching: e.g., "MIT" matches "mit", "Apache" matches "apache-2.0", "GPL" matches "gpl-2.0" or "gpl-3.0"
    if expected in actual_license_key or actual_license_key in expected:
        return 1

    return 0
Task: gitlab.update-license
Goal: Make the LICENSE of byteblaze/a11y-syntax-highlighting to one that mandates all copies and derivative works to be under the same license
Task configuration:
namespace: byteblaze
project_name: a11y-syntax-highlighting
license_type: GPL

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:

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

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

    expected_license = config.get("license") or config.get("license_type")

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

    # Build the url
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/projects/" + project_id + "?license=true"

    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()

    # Check if the license matches (flexible matching)
    actual_license_key = result["license"]["key"].lower().strip()
    expected = expected_license.lower().strip()

    # Direct match
    if actual_license_key == expected:
        return 1

    # Flexible matching: e.g., "MIT" matches "mit", "Apache" matches "apache-2.0", "GPL" matches "gpl-2.0" or "gpl-3.0"
    if expected in actual_license_key or actual_license_key in expected:
        return 1

    return 0
Task: gitlab.update-profile
Goal: set the homepage URL on my GitLab profile to https://egg.tart.com
Task configuration:
url: https://egg.tart.com

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
    if not "url" in config:
        raise ValueError("Target must contain 'url'")

    # Build the url
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/user"

    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()

    # Normalize URLs for comparison (GitLab may add http:// prefix)
    def normalize_url(url):
        url = url.lower().strip().rstrip("/")
        for prefix in ["https://", "http://"]:
            if url.startswith(prefix):
                url = url[len(prefix):]
        return url

    if normalize_url(result["website_url"]) == normalize_url(config["url"]):
        return 1
    return 0
Task: gitlab.update-profile
Goal: set the homepage URL on my GitLab profile to https://helloworld.xyz
Task configuration:
url: https://helloworld.xyz

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
    if not "url" in config:
        raise ValueError("Target must contain 'url'")

    # Build the url
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/user"

    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()

    # Normalize URLs for comparison (GitLab may add http:// prefix)
    def normalize_url(url):
        url = url.lower().strip().rstrip("/")
        for prefix in ["https://", "http://"]:
            if url.startswith(prefix):
                url = url[len(prefix):]
        return url

    if normalize_url(result["website_url"]) == normalize_url(config["url"]):
        return 1
    return 0
Task: gitlab.update-profile
Goal: set the homepage URL on my GitLab profile to a11yproject.contributor.me
Task configuration:
url: a11yproject.contributor.me

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
    if not "url" in config:
        raise ValueError("Target must contain 'url'")

    # Build the url
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/user"

    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()

    # Normalize URLs for comparison (GitLab may add http:// prefix)
    def normalize_url(url):
        url = url.lower().strip().rstrip("/")
        for prefix in ["https://", "http://"]:
            if url.startswith(prefix):
                url = url[len(prefix):]
        return url

    if normalize_url(result["website_url"]) == normalize_url(config["url"]):
        return 1
    return 0
Task: gitlab.update-profile
Goal: set the homepage URL on my GitLab profile to www.byteblaze.com
Task configuration:
url: www.byteblaze.com

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
    if not "url" in config:
        raise ValueError("Target must contain 'url'")

    # Build the url
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/user"

    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()

    # Normalize URLs for comparison (GitLab may add http:// prefix)
    def normalize_url(url):
        url = url.lower().strip().rstrip("/")
        for prefix in ["https://", "http://"]:
            if url.startswith(prefix):
                url = url[len(prefix):]
        return url

    if normalize_url(result["website_url"]) == normalize_url(config["url"]):
        return 1
    return 0
Task: gitlab.update-profile
Goal: set the homepage URL on my GitLab profile to byteblaze.github.io
Task configuration:
url: byteblaze.github.io

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
    if not "url" in config:
        raise ValueError("Target must contain 'url'")

    # Build the url
    url = os.getenv("GITLAB_BASE_URL", "").rstrip("/") + "/api/v4/user"

    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()

    # Normalize URLs for comparison (GitLab may add http:// prefix)
    def normalize_url(url):
        url = url.lower().strip().rstrip("/")
        for prefix in ["https://", "http://"]:
            if url.startswith(prefix):
                url = url[len(prefix):]
        return url

    if normalize_url(result["website_url"]) == normalize_url(config["url"]):
        return 1
    return 0
Task: gitlab.update-repo
Goal: Update the byteblaze/gimmiethat.space project site's title to "GIVE ME SPACE"
Task configuration:
namespace: byteblaze
project_name: gimmiethat.space
title: GIVE ME SPACE

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 "Welcome to my site"
Task configuration:
namespace: byteblaze
project_name: gimmiethat.space
title: Welcome to my site

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 "Not an interesting site"
Task configuration:
namespace: byteblaze
project_name: gimmiethat.space
title: Not an interesting site

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