<commit_before>// Description:
//   Manage the Trello Boards of your organization from Hubot!
//
// Dependencies:
//   "node-trello": "latest"
//
// Configuration:
//   HUBOT_TRELLO_KEY - Trello application key
//   HUBOT_TRELLO_TOKEN - Trello API token
//   HUBOT_TRELLO_ORGANIZATION - The ID or name of the Trello organisation
//
// Commands:
//   hubot trello help - Show detailed help to the trello hubot
//   hubot list boards - Show a list of boards of your Trello organization
//
//
// Author:
//   <NAME> <<EMAIL>>

var Trello = require('node-trello');
var trello = new Trello(process.env.HUBOT_TRELLO_KEY, process.env.HUBOT_TRELLO_TOKEN)

module.exports = function (robot) {

    // verify that all the environment vars are available
    function ensureConfig(out) {
        if (!process.env.HUBOT_TRELLO_KEY) {
            out("Error: Trello app key is not specified");
        }
        if (!process.env.HUBOT_TRELLO_TOKEN) {
            out("Error: Trello token is not specified");
        }
        if (!process.env.HUBOT_TRELLO_ORGANIZATION) {
            out("Error: Trello organization ID is not specified");
        }
        return true || process.env.HUBOT_TRELLO_KEY && process.env.HUBOT_TRELLO_TOKEN && process.env.HUBOT_TRELLO_ORGANIZATION;
    }

    // Finds the room for most adaptors
    function findRoom(msg) {
        var room = msg.envelope.room;
        if (room == undefined) {
            room = msg.envelope.user.reply_to;
        }
        return room;
    }

    // Updates the brain's  knowledge.
    function updateBrain(boards) {
        robot.brain.set('boards', boards);
    }

    // Returns all boards.
    function getBoards() {
        return robot.brain.get('boards') || {};
    }

    function getRoomBoard(msg) {
        var room = findRoom(msg);
        return getBoards()[room] || room;
    }
    function saveBoard(room, board) {
        var boards = getBoards();
        boards[room] = board;
        updateBrain(boards);
    }

    function findBoard(msg, callback) {
        var boardName = findRoom(msg);
        var savedBoardName = getBoards()[boardName];
        if (savedBoardName) {
            boardName = savedBoardName;
        }
        msg.reply("I'm loading the trello board " + boardName + ", first.");
        trello.get("/1/organizations/" + process.env.HUBOT_TRELLO_ORGANIZATION + "/boards", function (err, data) {
            if (err) {
                console.error(err);
                msg.reply("Sorry, but there was an error reading the list of boards.");
                return;
            }

            var boards = data.filter(function (board) {
                return board.name.toLowerCase() === boardName.toLowerCase();
            });

            if (boards && boards.length > 0) {
                callback(boards[0]);
            } else {
                msg.reply("Well, I couldn't find a board named: " + boardName + "?!");
            }
        });
    }

    function findList(msg, board, listName, callback) {
        trello.get("/1/boards/" + board.id + "/lists", function (err, data) {
            if (err) {
                console.error(err);
                msg.reply("Sorry, but there was an error reading the list of lists.");
                return;
            }
            var lists = data.filter(function (list) {
                return list.name.toLowerCase() === listName.toLowerCase();
            });
            if (lists && lists.length > 0) {
                callback(lists[0]);
            } else {
                msg.reply("I couldn't find a list named: " + listName + ".");
            }
        });
    }

    function findUser(msg, userName, callback) {
        trello.get("/1/organizations/" + process.env.HUBOT_TRELLO_ORGANIZATION + "/members", function (err, data) {
            if (err) {
                console.error(err);
                msg.reply("Sorry, but there was an error reading the list of members.");
                return;
            }
            var members = data.filter(function (member) {
                return username.name.toLowerCase() === userName.toLowerCase();
            });
            if (members && members.length > 0) {
                callback(members[0]);
            } else {
                msg.reply("I couldn't find a members with username: " + userName + ".");
            }
        });
    }

    // check the config first
    ensureConfig(console.log);

    // lists all the boards of the organisation
    robot.respond(/list boards$/i, function (msg) {
        msg.reply("Sure thing boss. I'll list the boards for you.");<commit_msg>Fix get member<commit_after>// Description:
//   Manage the Trello Boards of your organization from Hubot!
//
// Dependencies:
//   "node-trello": "latest"
//
// Configuration:
//   HUBOT_TRELLO_KEY - Trello application key
//   HUBOT_TRELLO_TOKEN - Trello API token
//   HUBOT_TRELLO_ORGANIZATION - The ID or name of the Trello organisation
//
// Commands:
//   hubot trello help - Show detailed help to the trello hubot
//   hubot list boards - Show a list of boards of your Trello organization
//
//
// Author:
//   <NAME> <<EMAIL>>

var Trello = require('node-trello');
var trello = new Trello(process.env.HUBOT_TRELLO_KEY, process.env.HUBOT_TRELLO_TOKEN)

module.exports = function (robot) {

    // verify that all the environment vars are available
    function ensureConfig(out) {
        if (!process.env.HUBOT_TRELLO_KEY) {
            out("Error: Trello app key is not specified");
        }
        if (!process.env.HUBOT_TRELLO_TOKEN) {
            out("Error: Trello token is not specified");
        }
        if (!process.env.HUBOT_TRELLO_ORGANIZATION) {
            out("Error: Trello organization ID is not specified");
        }
        return true || process.env.HUBOT_TRELLO_KEY && process.env.HUBOT_TRELLO_TOKEN && process.env.HUBOT_TRELLO_ORGANIZATION;
    }

    // Finds the room for most adaptors
    function findRoom(msg) {
        var room = msg.envelope.room;
        if (room == undefined) {
            room = msg.envelope.user.reply_to;
        }
        return room;
    }

    // Updates the brain's  knowledge.
    function updateBrain(boards) {
        robot.brain.set('boards', boards);
    }

    // Returns all boards.
    function getBoards() {
        return robot.brain.get('boards') || {};
    }

    function getRoomBoard(msg) {
        var room = findRoom(msg);
        return getBoards()[room] || room;
    }
    function saveBoard(room, board) {
        var boards = getBoards();
        boards[room] = board;
        updateBrain(boards);
    }

    function findBoard(msg, callback) {
        var boardName = findRoom(msg);
        var savedBoardName = getBoards()[boardName];
        if (savedBoardName) {
            boardName = savedBoardName;
        }
        msg.reply("I'm loading the trello board " + boardName + ", first.");
        trello.get("/1/organizations/" + process.env.HUBOT_TRELLO_ORGANIZATION + "/boards", function (err, data) {
            if (err) {
                console.error(err);
                msg.reply("Sorry, but there was an error reading the list of boards.");
                return;
            }

            var boards = data.filter(function (board) {
                return board.name.toLowerCase() === boardName.toLowerCase();
            });

            if (boards && boards.length > 0) {
                callback(boards[0]);
            } else {
                msg.reply("Well, I couldn't find a board named: " + boardName + "?!");
            }
        });
    }

    function findList(msg, board, listName, callback) {
        trello.get("/1/boards/" + board.id + "/lists", function (err, data) {
            if (err) {
                console.error(err);
                msg.reply("Sorry, but there was an error reading the list of lists.");
                return;
            }
            var lists = data.filter(function (list) {
                return list.name.toLowerCase() === listName.toLowerCase();
            });
            if (lists && lists.length > 0) {
                callback(lists[0]);
            } else {
                msg.reply("I couldn't find a list named: " + listName + ".");
            }
        });
    }

    function findUser(msg, userName, callback) {
        trello.get("/1/organizations/" + process.env.HUBOT_TRELLO_ORGANIZATION + "/members", function (err, data) {
            if (err) {
                console.error(err);
                msg.reply("Sorry, but there was an error reading the list of members.");
                return;
            }
            var members = data.filter(function (member) {
                return member.username.toLowerCase() === userName.toLowerCase();
            });
            if (members && members.length > 0) {
                callback(members[0]);
            } else {
                msg.reply("I couldn't find a members with username: " + userName + ".");
            }
        });
    }

    // check the config first
    ensureConfig(console.log);

    // lists all the boards of the organisation
    robot.respond(/list boards$/i, function (msg) {
        msg.reply("Sure thing boss. I'll list the boards for you.");
{'fraction_non_alphanumeric': 0.12218719426024569, 'fraction_numerical': 0.00195673442765518, 'mean_word_length': 1.8831087433406455, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2924283', 'n_tokens_mistral': 2721, 'n_tokens_neox': 2648, 'n_words': 679}