Commit 0cda5dd0 authored by Raniere Silva's avatar Raniere Silva
Browse files

Merge branch 'core' into gh-pages

parents ae935877 dfe4de76
Loading
Loading
Loading
Loading
+52 −10
Original line number Diff line number Diff line
@@ -667,6 +667,48 @@ def command_line():
    return parser.parse_args()


def check_required_files(dir_to_validate):
    """Check if required files exists."""
    REQUIRED_FILES = ["01-*.md",
                      "discussion.md",
                      "index.md",
                      "instructors.md",
                      "LICENSE.md",
                      "motivation.md",
                      "README.md",
                      "reference.md"]
    valid = True

    for required in REQUIRED_FILES:
        req_fn = os.path.join(dir_to_validate, required)
        if not glob.glob(req_fn):
            logging.error(
                "Missing file {0}.".format(required))
            valid = False

    return valid


def get_files_to_validate(file_or_path):
    """Generate list of files to validate."""
    files_to_validate = []
    dirs_to_validate = []

    for fn in file_or_path:
        if os.path.isdir(fn):
            search_str = os.path.join(fn, "*.md")
            files_to_validate.extend(glob.glob(search_str))
            dirs_to_validate.append(fn)
        elif os.path.isfile(fn):
            files_to_validate.append(fn)
        else:
            logging.error(
                "The specified file or folder {0} does not exist; "
                "could not perform validation".format(fn))

    return files_to_validate, dirs_to_validate


def main(parsed_args_obj):
    if parsed_args_obj.debug:
        log_level = "DEBUG"
@@ -677,16 +719,16 @@ def main(parsed_args_obj):
    template = parsed_args_obj.template

    all_valid = True
    for fn in parsed_args_obj.file_or_path:
        if os.path.isdir(fn):
            res = validate_folder(fn, template=template)
        elif os.path.isfile(fn):

    files_to_validate, dirs_to_validate = get_files_to_validate(
        parsed_args_obj.file_or_path)

    # If user ask to validate only one file don't check for required files.
    for d in dirs_to_validate:
        all_valid = all_valid and check_required_files(d)

    for fn in files_to_validate:
        res = validate_single(fn, template=template)
        else:
            res = False
            logging.error(
                "The specified file or folder {0} does not exist; "
                "could not perform validation".format(fn))

        all_valid = all_valid and res

+29 −12
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
##
##     $ tools/setup-label wking swc-modular-shell

CURL_FLAGS="--silent --fail"

if test $# -lt 2
then
    echo "Missing parameters."
@@ -28,8 +30,9 @@ fi
OWNER=$1
REPO=$2
GITHUB_URL=https://github.com/${OWNER}/${REPO}
LABELS=(getting-started working-in-progress discussion)
COLORS=(fbca04 f7c6c7 5319e7)
LABELS=(bug defer discussion duplicate enhancement filed-by-newcomer getting-started help-wanted left-as-was suitable-for-newcomer work-in-progress)
COLORS=(FF0000 66FF00 0000FF 98FB98 E0115F FFFF00 808000 89CFF0 568203 FCE883 545AA7)
LABELS_TO_DELETE=(help%20wanted invalid question wontfix)

# Test if repository exists
curl -s --head ${GITHUB_URL} | head -n 1 | grep -q "HTTP/1.[01] [23].."
@@ -46,22 +49,36 @@ read USERNAME
echo "Your GitHub password:"
read -s PASSWORD

# Delete labels
for INDEX in $(seq 0 $((${#LABELS_TO_DELETE[*]} - 1)))
do
    # Try to delete label
    curl ${CURL_FLAGS} -X DELETE \
        -u ${USERNAME}:${PASSWORD} \
        "https://api.github.com/repos/${OWNER}/${REPO}/labels/${LABELS_TO_DELETE[${INDEX}]}" > /dev/null
done
# Create labels
for INDEX in $(seq 1 ${#LABELS[*]})
for INDEX in $(seq 0 $((${#LABELS[*]} - 1)))
do
    curl -s -f -X POST \
    # Try create new label
    curl ${CURL_FLAGS} -X POST \
        -u ${USERNAME}:${PASSWORD} \
        -d "{\"name\":\"${LABELS[${INDEX}]}\",\"color\":\"${COLORS[${INDEX}]}\"}" \
        "https://api.github.com/repos/${OWNER}/${REPO}/labels" > /dev/null
    if test $? -ne 0
    then
        echo "Failed when trying to create the label ${LABELS[${INDEX}]}."
        echo "Probably the label ${LABELS[${INDEX}]} already exists."
        echo "Please check at ${GITHUB_URL}/labels or run"
        echo
        echo "    $ curl -X POST -u ${USERNAME} -d \"{\"name\":\"${LABELS[${INDEX}]}\",\"color\":\"${COLORS[${INDEX}]}\"}\" \"https://api.github.com/repos/${OWNER}/${REPO}/labels\""
        echo
        echo "to get more information of the error. If you find a bug"
        echo "report it at https://github.com/swcarpentry/lesson-template/."
        # Try to fix label color
        curl ${CURL_FLAGS} -X PATCH \
            -u ${USERNAME}:${PASSWORD} \
            -d "{\"name\":\"${LABELS[${INDEX}]}\",\"color\":\"${COLORS[${INDEX}]}\"}" \
            "https://api.github.com/repos/${OWNER}/${REPO}/labels/${LABELS[${INDEX}]}" > /dev/null
        if test $? -ne 0
        then
            echo "Failed when trying to create and update the label ${LABELS[${INDEX}]}."
            echo "Please check at ${GITHUB_URL}/labels"
            echo ""
            echo "If you find a bug report it at"
            echo "https://github.com/swcarpentry/lesson-template/."
        fi
    fi
done