Giter VIP home page Giter VIP logo

watson-ruby's Issues

Keep *.swp in there? [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 229
tag : review
md5 : a5997989bb0082344f36df9e86a80676

        # [review] - Keep *.swp in there?
        # [todo] - Add conditional to @rc_file such that if passed by -f we accept it
        # [todo] - Add current file (watson) to avoid accidentally printing app tags 
        @ignore_list.push(".")
        @ignore_list.push("..")
        @ignore_list.push("*.swp")
        @ignore_list.push(@rc_file)
        @ignore_list.push(@tmp_file)
            # Open and read rc
        # [review] - Not sure if explicit file close is required here
        _rc = File.open(@rc_file, 'r').read

        debug_print "\n\n"  

        # Create temp section var to keep track of what we are populating in config
        _section = ""

Should command line args append or overwrite config/RC parameters? [lib/watson/command.rb]

filename : lib/watson/command.rb
line # : 19
tag : review
md5 : 09b421d74dc4a5721a92c766da0a14d8

    # [review] - Should command line args append or overwrite config/RC parameters?
    #            Currently we overwrite, maybe add flag to overwrite or not?
            # Identify method entry
        debug_print "#{ self } : #{ __method__ }\n"

        # List of possible flags, used later in parsing and for user reference
        _flag_list = ["-c", "--context-depth",
                      "-d", "--dirs",
                      "-f", "--files",
                      "-h", "--help",
                      "-i", "--ignore",
                      "-p", "--parse-depth",
                      "-r", "--remote",
                      "-t", "--tags",
                      "-u", "--update",
                      "-v", "--version"

Populate @tag_list, then check size instead [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 336
tag : review
md5 : 0712ce13f6ce50af74864296a3b53a65

# [review] - Populate @tag_list, then check size instead

if @cl_ignore_set
    debug_print "Ignores set from command line, ignoring rc [ignores]\n"
    next
end

# Same as previous for ignores (regex same as dirs)
# Don't eliminate trailing / because not sure if dir can have
# same name as file (Linux it can't, but not sure about Win/Mac)
# [review] - Can Win/Mac have dir + file with same name in same dir?
_mtch = _line.match(/^((\w+)?\.?\/?)+/)[0]
if !_mtch.empty?
    @ignore_list.push(_mtch) 
    debug_print "#{ _mtch } added to @ignore_list\n"
end
debug_print "@ignore_list --> #{ @ignore_list }\n"

Only give relative path for privacy when posted [lib/watson/bitbucket.rb]

filename : lib/watson/bitbucket.rb
line # : 333
tag : review
md5 : b6c50191344a9be3e454e249d73a84d9

# [review] - Only give relative path for privacy when posted
_body = "__filename__ : #{ issue[:path] }  \n" +
        "__line #__ : #{ issue[:line_number] }  \n" + 
        "__tag__ : #{ issue[:tag] }  \n" +
        "__md5__ : #{ issue[:md5] }  \n\n" +
        "#{ issue[:context].join }"

# Create option hash to pass to Remote::http_call
# Issues URL for GitHub + SSL
# No tag or label concept in Bitbucket unfortunately :(
opts = {:url        => "https://bitbucket.org/api/1.0/repositories/#{ config.bitbucket_api }/#{ config.bitbucket_repo }/issues",
        :ssl        => true,
        :method     => "POST",
        :basic_auth => [config.bitbucket_api, config.bitbucket_pw],
        :data       => [{"title" => issue[:title] + " [#{ issue[:path] }]",
                        "content" => _body }],
        :verbose    => false 

Keep asking for user data until valid instead of leaving app [lib/watson/github.rb]

filename : lib/watson/github.rb
line # : 16
tag : todo
md5 : 81579429f4cfb33acfdbbc4fbccb8a35

    # [todo] - Keep asking for user data until valid instead of leaving app
            # Include for debug_print
    include Watson

    #############################################################################   
    # Setup remote access to GitHub 
    # Get Username, Repo, and PW and perform necessary HTTP calls to check validity
    def setup(config)
            # Identify method entry
        debug_print "#{ self.class } : #{ __method__ }\n"

        Printer.print_status "+", GREEN
        print BOLD + "Obtaining OAuth Token for GitHub...\n" + RESET

Not sure if explicit file close is required here [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 423
tag : review
md5 : ae184abbc1e4155a7575a3adb8c2c1b8

        # [review] - Not sure if explicit file close is required here
        _rc = File.open(@rc_file, 'r').read
        _update = File.open(@rc_file, 'w')


        # Keep index to print what line we are on
        # Could fool around with Enumerable + each_with_index but oh well
        _i = 0;
            # Keep track of newlines for prettying up the conf
        _nlc = 0
        _section = ""
            # Fix line endings so we can support Windows/Linux edited rc files
        _rc.gsub!(/\r\n?/, "\n")
        _rc.each_line do | _line |
            # Print line for debug purposes

Make this a non-debug print to user? [lib/watson/command.rb]

filename : lib/watson/command.rb
line # : 260
tag : review
md5 : 2d8b0c860d5920215c042aa05acc948a

            # [review] - Make this a non-debug print to user?
            debug_print "No args passed, exiting\n"
            return false
        end
            # Set config flag for CL entryset  in config
        @config.cl_entry_set = true 
        debug_print "Updated cl_entry_set flag: #{ @config.cl_entry_set }\n"

        # [review] - Should we clean the dir before adding here?
        # For each argument passed, make sure valid, then add to @config.dir_list
        args.each do | _dir |
            # Error check on input
            if !Watson::FS.check_dir(_dir)
                print "Unable to open #{ _dir }\n"
            else
                # Clean up directory path

This is a bit messy (to slice by _i - 1) when we have control [lib/watson/command.rb]

filename : lib/watson/command.rb
line # : 98
tag : review
md5 : 6cd359037bd5d372ceac24e9bbb9e4d9

            # [review] - This is a bit messy (to slice by _i - 1) when we have control
            # over the _i index above but I don't want to
            # think about the logic right now so look at later
            _flag_args = args.slice!(0..(_i-1))
                case _flag 
            when "-c", "--context-depth"
                debug_print "Found -c/--context-depth argument\n"
                set_context(_flag_args)
                when "-d", "--dirs"
                debug_print "Found -d/--dirs argument\n"
                set_dirs(_flag_args)

            when "-f", "--files"
                debug_print "Found -f/--files argument\n"
                set_files(_flag_args)

Allow closing of issues from watson? Don't like that idea but maybe [lib/watson/bitbucket.rb]

filename : lib/watson/bitbucket.rb
line # : 13
tag : todo
md5 : e57eb5ea1ceb66d6f0b9e53b8885129e

# [todo] - Allow closing of issues from watson? Don't like that idea but maybe
# [todo] - Wrap Bitbucket password grabbing into separate method
    # Include for debug_print
include Watson
    #############################################################################   
# Setup remote access to Bitbucket
# Get Username, Repo, and PW and perform necessary HTTP calls to check validity
def setup(config)

    # Identify method entry
    debug_print "#{ self.class } : #{ __method__ }\n"

    Printer.print_status "+", GREEN
    print BOLD +  "Attempting to access Bitbucket...\n" + RESET

Change debug_print to provide its own \n [lib/watson.rb]

filename : lib/watson.rb
line # : 15
tag : todo
md5 : db012a37f91895a2229eb38f0de53e3d

# [todo] - Change debug_print to provide its own \n

# [todo] - Add ability to pass "IDENTIFY" to debug_print to auto print method entry info 

# [todo] - Make sure all methods have proper return at end

# [review] - Method input arg always renamed from arg to _arg inside method, change this?
#            Not sure if I should just make input arg _arg or if explicit _ is useful 

# [todo] - Add option to save output to specified file
# [todo] - Replace Identify line in each method with method_added call
#          http://ruby-doc.org/core-2.0.0/Module.html#method-i-method_added
    # Separate ON and OFF so we can force state and still let 
# individual classes have some control over their prints
    # Global flag to turn ON debugging across all files

Populate @tag_list, then check size instead [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 316
tag : review
md5 : 0712ce13f6ce50af74864296a3b53a65

                # [review] - Populate @tag_list, then check size instead
                if @cl_tag_set
                    debug_print "Tags set from command line, ignoring rc [tags]\n"
                    next 
                end
                    # Same as previous for tags
                # [review] - Need to think about what kind of tags this supports
                # Check compatibility with GitHub + Bitbucket and what makes sense
                # Only supports single word+number tags
                _mtch = _line.match(/^(\S+)/)[0]
                if !_mtch.empty?
                    @tag_list.push(_mtch)
                    debug_print "#{ _mtch } added to @tag_list\n"
                end
                debug_print "@tag_list --> #{ @tag_list }\n"

Read and store rc FP inside initialize? [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 70
tag : review
md5 : 21917160148caa0b73c4af43307f87b9

    # [review] - Read and store rc FP inside initialize?
    # This way we don't need to keep reopening the FP to use it
    # but then we need a way to reliably close the FP when done 

        # Identify method entry
        debug_print "#{self.class} : #{__method__}\n"
            # Program config
        @rc_file        = ".watsonrc"
        @tmp_file       = ".watsonresults"
            @parse_depth    = 0
        @context_depth  = 15
            # State flags
        @cl_entry_set   = false
        @cl_tag_set     = false

Not sure this is the correct place to put the Ctrl+C capture [lib/watson/command.rb]

filename : lib/watson/command.rb
line # : 60
tag : review
md5 : 9b282879834ad99eba631c996578d8d0

        # [review] - Not sure this is the correct place to put the Ctrl+C capture
        trap("INT") do
            File.delete(@config.tmp_file) if File.exists?(@config.tmp_file)
            exit 2
        end
            # Parse command line options
        # Begin by slicing off until we reach a valid flag

        # Always look at first array element in case and then slice off what we need
        # Accept parameters to be added / overwritten if called twice
        # Slice out from argument until next argument

        # Clean up argument list by removing elements until the first valid flag    
        until _flag_list.include?(args[0]) || args.length == 0
            # [review] - Make this non-debug print to user?
            debug_print "Unrecognized flag #{ args[0] }\n"

Method input arg always renamed from arg to _arg inside method, change this? [lib/watson.rb]

filename : lib/watson.rb
line # : 21
tag : review
md5 : 884d38a348a7dc8518e2e226bffc96ad

# [review] - Method input arg always renamed from arg to _arg inside method, change this?
#            Not sure if I should just make input arg _arg or if explicit _ is useful 

# [todo] - Add option to save output to specified file
# [todo] - Replace Identify line in each method with method_added call
#          http://ruby-doc.org/core-2.0.0/Module.html#method-i-method_added
    # Separate ON and OFF so we can force state and still let 
# individual classes have some control over their prints
    # Global flag to turn ON debugging across all files
GLOBAL_DEBUG_ON = false
# Gllobal flag to turn OFF debugging across all files
GLOBAL_DEBUG_OFF = false 
    # [review] - Not sure if module_function is proper way to scope
# I want to be able to call debug_print without having to use the scope

Populate @dirs/files_list first, then check size instead [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 297
tag : review
md5 : fa180c7d5ae2f4c9b93042a49c1ae11c

                # [review] - Populate @dirs/files_list first, then check size instead
                if @cl_entry_set
                    debug_print "Directories or files set from command line ignoring rc [dirs]\n"
                    next 
                end

                # Regex to grab directory
                # Then substitute trailing / (necessary for later formatting)
                # Then push to @dir_list
                _mtch = _line.match(/^((\w+)?\.?\/?)+/)[0].gsub(/(\/)+$/, "")
                if !_mtch.empty?
                    @dir_list.push(_mtch) 
                    debug_print "#{ _mtch } added to @dir_list\n"
                end
                debug_print "@dir_list --> #{ @dir_list }\n"

Don't just check for blank password but invalid as well [lib/watson/github.rb]

filename : lib/watson/github.rb
line # : 55
tag : todo
md5 : 5f9156ff58811fb89fbad8bd977d2a4b

        # [todo] - Don't just check for blank password but invalid as well
        # Poor mans username/password grabbing
        print BOLD + "Username: " + RESET
        _username = $stdin.gets.chomp
        if _username.empty?
            Printer.print_status "x", RED
            print BOLD + "Input blank. Please enter your username!\n\n" + RESET
            return false
        end
            # [fix] - Crossplatform password block needed, not sure if current method is safe either
        # Block output to tty to prevent PW showing, Linux/Unix only :(
        print BOLD + "Password: " + RESET
        system "stty -echo"
        _password = $stdin.gets.chomp
        system "stty echo"
        print "\n\n"

Add current file (watson) to avoid accidentally printing app tags [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 231
tag : todo
md5 : 04702c2887bb3056b7598de144c516a9

        # [todo] - Add current file (watson) to avoid accidentally printing app tags 
        @ignore_list.push(".")
        @ignore_list.push("..")
        @ignore_list.push("*.swp")
        @ignore_list.push(@rc_file)
        @ignore_list.push(@tmp_file)
            # Open and read rc
        # [review] - Not sure if explicit file close is required here
        _rc = File.open(@rc_file, 'r').read

        debug_print "\n\n"  

        # Create temp section var to keep track of what we are populating in config
        _section = ""

        # Keep index to print what line we are on

Not sure whether to make check* methods return FP [lib/watson/fs.rb]

filename : lib/watson/fs.rb
line # : 10
tag : todo
md5 : d4a7ed9ab5de76f7b8183e60e49d0f29

    # [todo] - Not sure whether to make check* methods return FP
    #          Makes it nice to get it returned and use it but
    #          not sure how to deal with closing the FP after
    #          Currently just close inside
        # Include for debug_print
    include Watson

    ###########################################################
    # Check if file exists and can be opened
    def check_file(file)

        # Identify method entry
        debug_print "#{ self } : #{ __method__ }\n"

        # Error check for input
        if file.length == 0

Play with idea of making body of GitHub issue hash format to be exec'd [lib/watson/bitbucket.rb]

filename : lib/watson/bitbucket.rb
line # : 282
tag : todo
md5 : 31546491cd844675df481310dc1571ba

# [todo] - Play with idea of making body of GitHub issue hash format to be exec'd
#          Store pieces in text as :md5 => "whatever" so when we get issues we can
#          call exec and turn it into a real hash for parsing in watson
#          Makes watson code cleaner but not as readable comment on GitHub...?
debug_print "Checking open issues to see if already posted\n"
config.bitbucket_issues[:open].each do | _open | 
    if _open["content"].include?(issue[:md5])
        debug_print "Found in #{ _open["title"] }, not posting\n"
        return false
    end
    debug_print "Did not find in #{_open["title"]}\n"
end 

debug_print "Checking closed issues to see if already posted\n"
config.bitbucket_issues[:closed].each do  | _closed | 
    if _closed["content"].include?(issue[:md5])
        debug_print "Found in #{ _closed["title"] }, not posting\n"

Should we clean the dir before adding here? [lib/watson/command.rb]

filename : lib/watson/command.rb
line # : 269
tag : review
md5 : d80c71d6d9f52b99a0eb046266425638

        # [review] - Should we clean the dir before adding here?
        # For each argument passed, make sure valid, then add to @config.dir_list
        args.each do | _dir |
            # Error check on input
            if !Watson::FS.check_dir(_dir)
                print "Unable to open #{ _dir }\n"
            else
                # Clean up directory path
                _dir = _dir.match(/^((\w+)?\.?\/?)+/)[0].gsub(/(\/)+$/, "")
                if !_dir.empty?
                    debug_print "Adding #{ _dir } to config dir_list\n"
                    @config.dir_list.push(_dir)
                end
            end
        end
            debug_print "Updated dirs: #{ @config.dir_list }\n"

Better way to identify/compare remote->local issues than md5 [lib/watson/bitbucket.rb]

filename : lib/watson/bitbucket.rb
line # : 267
tag : todo
md5 : c6b521f8a16501ae7813caf8da1e5b1a

    # [todo] - Better way to identify/compare remote->local issues than md5
    #          Current md5 based on some things that easily can change, need better ident
            # Identify method entry
        debug_print "#{self.class} : #{__method__}\n"


        # Only attempt to get issues if API is specified 
        if config.bitbucket_api.empty?
            debug_print "No API found, this shouldn't be called...\n"
            return false
        end
            # Check that issue hasn't been posted already by comparing md5s
        # Go through all open issues, if there is a match in md5, return out of method
        # [todo] - Play with idea of making body of GitHub issue hash format to be exec'd
        #          Store pieces in text as :md5 => "whatever" so when we get issues we can

Make sure all methods have proper return at end [lib/watson.rb]

filename : lib/watson.rb
line # : 19
tag : todo
md5 : a8bb1b568d6b99d37be56c5865fdc965

# [todo] - Make sure all methods have proper return at end

# [review] - Method input arg always renamed from arg to _arg inside method, change this?
#            Not sure if I should just make input arg _arg or if explicit _ is useful 

# [todo] - Add option to save output to specified file
# [todo] - Replace Identify line in each method with method_added call
#          http://ruby-doc.org/core-2.0.0/Module.html#method-i-method_added
    # Separate ON and OFF so we can force state and still let 
# individual classes have some control over their prints
    # Global flag to turn ON debugging across all files
GLOBAL_DEBUG_ON = false
# Gllobal flag to turn OFF debugging across all files
GLOBAL_DEBUG_OFF = false 

Combine into single statement (for performance or something?) [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 13
tag : review
md5 : 65c2f0e70fff3011713c2d9fb7d77d05

    # [review] - Combine into single statement (for performance or something?)
    # [todo] - Add config options (rc file) for default max depth and context lines
        # List of all files/folders to ignore when parsing  
    attr_accessor :ignore_list
    # List of directories to parse  
    attr_accessor :dir_list
    # List of all files to parse
    attr_accessor :file_list        
    # List of tags to look for when parsing
    attr_accessor :tag_list         
    # Number of directories to parse recursively
    attr_accessor :parse_depth
    # Number of lines of issue context to grab
    attr_accessor :context_depth    
        # Flag for command line setting of file/dir to parse

Use if with match so we can call next on the line reading loop [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 266
tag : review
md5 : 6642f7af20c07b5ad49b005bb5466c72

            # [review] - Use if with match so we can call next on the line reading loop
            # Tried using match(){|_mtch|} as well as do |_mtch| but those don't seem to
            # register the next call to the outer loop, so this way will do for now
                # Regex on line to find out if we are in a new [section] of
            # config parameters. If so, store it into section var and move
            # to next line 
            _mtch = _line.match(/^\[(\w+)\]/)
            if _mtch
                debug_print "Found section #{ _mtch[1] }\n"
                _section = _mtch[1]
                next
            end
                    case _section
            when "context_depth"

More "Ruby" way of going to next line? [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 261
tag : review
md5 : eb83bcdeb3e78f7c5783b6e1008ae470

                # [review] - More "Ruby" way of going to next line?
                next
            end


            # [review] - Use if with match so we can call next on the line reading loop
            # Tried using match(){|_mtch|} as well as do |_mtch| but those don't seem to
            # register the next call to the outer loop, so this way will do for now
                # Regex on line to find out if we are in a new [section] of
            # config parameters. If so, store it into section var and move
            # to next line 
            _mtch = _line.match(/^\[(\w+)\]/)
            if _mtch
                debug_print "Found section #{ _mtch[1] }\n"
                _section = _mtch[1]
                next

Add option to save output to specified file [lib/watson.rb]

filename : lib/watson.rb
line # : 24
tag : todo
md5 : 8b50ce58f658f01b266097e97d68f6cb

# [todo] - Add option to save output to specified file
# [todo] - Replace Identify line in each method with method_added call
#          http://ruby-doc.org/core-2.0.0/Module.html#method-i-method_added
    # Separate ON and OFF so we can force state and still let 
# individual classes have some control over their prints
    # Global flag to turn ON debugging across all files
GLOBAL_DEBUG_ON = false
# Gllobal flag to turn OFF debugging across all files
GLOBAL_DEBUG_OFF = false 
    # [review] - Not sure if module_function is proper way to scope
# I want to be able to call debug_print without having to use the scope
# operator (Watson::Printer.debug_print) so it is defined here as a 
# module_function instead of having it in the Printer class
# Gets included into every class individually

Add conditional to @rc_file such that if passed by -f we accept it [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 230
tag : todo
md5 : f0cf8a1a187180dc2bd40efe4120cebc

        # [todo] - Add conditional to @rc_file such that if passed by -f we accept it
        # [todo] - Add current file (watson) to avoid accidentally printing app tags 
        @ignore_list.push(".")
        @ignore_list.push("..")
        @ignore_list.push("*.swp")
        @ignore_list.push(@rc_file)
        @ignore_list.push(@tmp_file)
            # Open and read rc
        # [review] - Not sure if explicit file close is required here
        _rc = File.open(@rc_file, 'r').read

        debug_print "\n\n"  

        # Create temp section var to keep track of what we are populating in config
        _section = ""

Can Win/Mac have dir + file with same name in same dir? [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 346
tag : review
md5 : 4d923a34cb0a917a31a6a74ed9bd30c9

                # [review] - Can Win/Mac have dir + file with same name in same dir?
                _mtch = _line.match(/^((\w+)?\.?\/?)+/)[0]
                if !_mtch.empty?
                    @ignore_list.push(_mtch) 
                    debug_print "#{ _mtch } added to @ignore_list\n"
                end
                debug_print "@ignore_list --> #{ @ignore_list }\n"

            when "github_api"
                # No need for regex on API key, GitHub setup should do this properly
                # Chomp to get rid of any nonsense
                @github_api = _line.chomp!
                debug_print "GitHub API: #{ @github_api }\n"

            when "github_repo"

Not a fan of running these here but want to avoid getting all issues when running remote (which @config.run does) [lib/watson/command.rb]

filename : lib/watson/command.rb
line # : 127
tag : review
md5 : 00bdc95b47067889ef9c1ab4ce01f0c6

                # [review] - Not a fan of running these here but want to avoid getting all issues when running remote (which @config.run does)
                @config.check_conf
                @config.read_conf
                setup_remote(_flag_args)

                # If setting up remote, exit afterwards
                exit true

            when "-t", "--tags"
                debug_print "Found -t/--tags argument\n"
                set_tags(_flag_args)
                when "-u", "--update"
                debug_print "Found -u/--update argument\n"
                @config.remote_valid =  true

Bitbucket OAuth not implemented yet so warn user about HTTP Auth [lib/watson/bitbucket.rb]

filename : lib/watson/bitbucket.rb
line # : 52
tag : todo
md5 : 67d1a8fa1d841d30d4a3d7ff1ec86829

        # [todo] - Bitbucket OAuth not implemented yet so warn user about HTTP Auth
        # Bitbucket doesn't have nonOAuth flow that GitHub does :(
        # Even if I use OAuth lib, still need to validate from webview which is lame
        Printer.print_status "!", RED 
        print BOLD + "Bitbucket OAuth not implemented yet.\n" + RESET;
        print "      Basic HTTP Auth in use, will request PW entry every time.\n\n"
                # [todo] - Don't just check for blank password but invalid as well
        # Poor mans username/password grabbing
        print BOLD + "Username: " + RESET
        _username = $stdin.gets.chomp
        if _username.empty?
            Printer.print_status "x", RED
            print BOLD + "Input blank. Please enter your username!\n\n" + RESET
            return false
        end

Make this non-debug print to user? [lib/watson/command.rb]

filename : lib/watson/command.rb
line # : 75
tag : review
md5 : 134b270988d5245c6371b9eb547ee0fa

            # [review] - Make this non-debug print to user?
            debug_print "Unrecognized flag #{ args[0] }\n"
            args.slice!(0)
        end

        # Parse command line options
        # Grab flag (should be first arg) then slice off args until next flag
        # Repeat until all args have been dealt with
            until args.length == 0
            # Set flag for calling function later
            _flag = args.slice!(0)
                debug_print "Current Flag: #{ _flag }\n"
                # Go through args until we find the next valid flag or all args are parsed 
            _i = 0

Not sure if I should use the open/read/write or Fileutils.cp [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 171
tag : review
md5 : 0a12ea7e18c69f84fd01bb67bc743921

    # [review] - Not sure if I should use the open/read/write or Fileutils.cp

        # Identify method entry
        debug_print "#{ self.class } : #{ __method__ }\n"

        # Generate full path since File doesn't care about the LOAD_PATH
        # [review] - gsub uses (.?)+ to grab anything after lib (optional), better regex? 
        _full_path = __dir__.gsub(/\/lib(.?)+/, '') + "/" + "assets/defaultConf"
        debug_print "Full path to defaultConf (in gem): #{ _full_path }\n"

        # Check to make sure we can access the default file
        if !Watson::FS.check_file(_full_path)
            print "Unable to open #{ _full_path }\n"
            print "Cannot create default, exiting...\n"
            return false
        else

Add config options (rc file) for default max depth and context lines [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 14
tag : todo
md5 : 1b2e201cf223a760d7955d00173bda82

    # [todo] - Add config options (rc file) for default max depth and context lines
        # List of all files/folders to ignore when parsing  
    attr_accessor :ignore_list
    # List of directories to parse  
    attr_accessor :dir_list
    # List of all files to parse
    attr_accessor :file_list        
    # List of tags to look for when parsing
    attr_accessor :tag_list         
    # Number of directories to parse recursively
    attr_accessor :parse_depth
    # Number of lines of issue context to grab
    attr_accessor :context_depth    
        # Flag for command line setting of file/dir to parse
    attr_accessor :cl_entry_set

Need to think about what kind of tags this supports [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 323
tag : review
md5 : fc8255717a95e49635f126006327aa9d

                # [review] - Need to think about what kind of tags this supports
                # Check compatibility with GitHub + Bitbucket and what makes sense
                # Only supports single word+number tags
                _mtch = _line.match(/^(\S+)/)[0]
                if !_mtch.empty?
                    @tag_list.push(_mtch)
                    debug_print "#{ _mtch } added to @tag_list\n"
                end
                debug_print "@tag_list --> #{ @tag_list }\n"

                when "ignore"
                # Same as previous for ignores
                # [review] - Populate @tag_list, then check size instead

                if @cl_ignore_set
                    debug_print "Ignores set from command line, ignoring rc [ignores]\n"

Replace Identify line in each method with method_added call [lib/watson.rb]

filename : lib/watson.rb
line # : 25
tag : todo
md5 : c53b361c0321aa080aad1df039a731c1

# [todo] - Replace Identify line in each method with method_added call
#          http://ruby-doc.org/core-2.0.0/Module.html#method-i-method_added
    # Separate ON and OFF so we can force state and still let 
# individual classes have some control over their prints
    # Global flag to turn ON debugging across all files
GLOBAL_DEBUG_ON = false
# Gllobal flag to turn OFF debugging across all files
GLOBAL_DEBUG_OFF = false 
    # [review] - Not sure if module_function is proper way to scope
# I want to be able to call debug_print without having to use the scope
# operator (Watson::Printer.debug_print) so it is defined here as a 
# module_function instead of having it in the Printer class
# Gets included into every class individually
module_function

Replace all regex parentheses() with brackets[] if not matching [lib/watson.rb]

filename : lib/watson.rb
line # : 11
tag : todo
md5 : 8ce0c4810e13203e90c89c49429bde64

# [todo] - Replace all regex parentheses() with brackets[] if not matching
#          Was using () to group things together for syntax instead of []
#          Replace so we can get cleaner matches and don't need to keep track of matches

# [todo] - Change debug_print to provide its own \n

# [todo] - Add ability to pass "IDENTIFY" to debug_print to auto print method entry info 

# [todo] - Make sure all methods have proper return at end

# [review] - Method input arg always renamed from arg to _arg inside method, change this?
#            Not sure if I should just make input arg _arg or if explicit _ is useful 

# [todo] - Add option to save output to specified file
# [todo] - Replace Identify line in each method with method_added call
#          http://ruby-doc.org/core-2.0.0/Module.html#method-i-method_added

Add ability to pass "IDENTIFY" to debug_print to auto print method entry info [lib/watson.rb]

filename : lib/watson.rb
line # : 17
tag : todo
md5 : 5d8f7aec945fccf26d0ee22c94c1cdba

# [todo] - Add ability to pass "IDENTIFY" to debug_print to auto print method entry info 

# [todo] - Make sure all methods have proper return at end

# [review] - Method input arg always renamed from arg to _arg inside method, change this?
#            Not sure if I should just make input arg _arg or if explicit _ is useful 

# [todo] - Add option to save output to specified file
# [todo] - Replace Identify line in each method with method_added call
#          http://ruby-doc.org/core-2.0.0/Module.html#method-i-method_added
    # Separate ON and OFF so we can force state and still let 
# individual classes have some control over their prints
    # Global flag to turn ON debugging across all files
GLOBAL_DEBUG_ON = false
# Gllobal flag to turn OFF debugging across all files

Add bold and colored printing [lib/watson/command.rb]

filename : lib/watson/command.rb
line # : 159
tag : todo
md5 : 352d5fd0d508d1dd5b0c29b1ed21fb5e

    # [todo] - Add bold and colored printing

        # Identify method entry
        debug_print "#{ self } : #{ __method__ }\n"

        print BOLD;
        print "Usage: watson [OPTION]...\n"
        print "Running watson with no arguments will parse with settings in RC file\n"
        print "If no RC file exists, default RC file will be created\n"
            print "\n"
        print "   -c, --context-depth   number of lines of context to provide with posted issue\n"
        print "   -d, --dirs            list of directories to search in\n"
        print "   -f, --files           list of files to search in\n"
        print "   -h, --help            print help\n"
        print "   -i, --ignore          list of files, directories, or types to ignore\n"
        print "   -p, --parse-depth     depth to recursively parse directories\n"

Add option to save output to file also [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 90
tag : todo
md5 : 8c2cca11be5bb9238647bba4868ec6e4

        # [todo] - Add option to save output to file also
        @use_less = false
            # Data containers
        @ignore_list    = Array.new()
        @dir_list       = Array.new()
        @file_list      = Array.new()
        @tag_list       = Array.new()

        # Remote options
        @remote_valid   = false

        @github_valid   = false
        @github_api     = ""
        @github_repo    = ""
        @github_issues  = {:open   => Hash.new(),
                          :closed => Hash.new()

Crossplatform password block needed, not sure if current method is safe either [lib/watson/bitbucket.rb]

filename : lib/watson/bitbucket.rb
line # : 99
tag : fix
md5 : 63005a1dc174a3a608b3efa79a983baa

        # [fix] - Crossplatform password block needed, not sure if current method is safe either
        # Block output to tty to prevent PW showing, Linux/Unix only :(
        print BOLD + "Password: " + RESET
        system "stty -echo"
        _password = $stdin.gets.chomp
        system "stty echo"
        print "\n"
        if _password.empty?
            Printer.print_status "x", RED
            print BOLD + "Input is blank. Please enter your password!\n\n" + RESET
            return false
        end
            # HTTP Request to check if Repo exists and user has access 
        # http://confluence.atlassian.com/display/BITBUCKET/Use+the+Bitbucket+REST+APIs 
            # Create options hash to pass to Remote::http_call 

Not sure if module_function is proper way to scope [lib/watson.rb]

filename : lib/watson.rb
line # : 36
tag : review
md5 : 689efffa625cb16851d04b12478c5cc4

# [review] - Not sure if module_function is proper way to scope
# I want to be able to call debug_print without having to use the scope
# operator (Watson::Printer.debug_print) so it is defined here as a 
# module_function instead of having it in the Printer class
# Gets included into every class individually
module_function

###########################################################
# Global debug print that prints based on local file DEBUG flag as well as GLOBAL debug flag 
def debug_print(msg)
# [todo] - If input msg is a Hash, use pp to dump it
        # Print only if DEBUG flag of calling class is true OR 
    # GLOBAL_DEBUG_ON of Watson module (defined above) is true
    # AND GLOBAL_DEBUG_OFF of Watson module (Defined above) is false
        # Sometimes we call debug_print from a static method (class << self)

Make this a non-debug print to user? [lib/watson/command.rb]

filename : lib/watson/command.rb
line # : 224
tag : review
md5 : 2d8b0c860d5920215c042aa05acc948a

            # [review] - Make this a non-debug print to user?
            debug_print "No args passed, exiting\n"
            return false
        end

        # For context_depth we do NOT append to RC, ALWAYS overwrite
        # For each argument passed, make sure valid, then set @config.parse_depth 
        args.each do | _context_depth |
            if _context_depth.match(/^(\d+)/)
                debug_print "Setting #{ _context_depth } to config context_depth\n" 
                @config.context_depth = _context_depth.to_i
            else
                debug_print "#{ _context_depth } invalid depth, ignoring\n"
            end
        end

Allow closing of issues from watson? Don't like that idea but maybe [lib/watson/github.rb]

filename : lib/watson/github.rb
line # : 13
tag : todo
md5 : d327ee0fc8672c86df6c9d177ef2e81c

    # [todo] - Allow closing of issues from watson? Don't like that idea but maybe
    # [review] - Properly scope Printer class so we dont need the Printer. for 
    #            method calls?
    # [todo] - Keep asking for user data until valid instead of leaving app
            # Include for debug_print
    include Watson

    #############################################################################   
    # Setup remote access to GitHub 
    # Get Username, Repo, and PW and perform necessary HTTP calls to check validity
    def setup(config)
            # Identify method entry
        debug_print "#{ self.class } : #{ __method__ }\n"

Don't just check for blank password but invalid as well [lib/watson/bitbucket.rb]

filename : lib/watson/bitbucket.rb
line # : 60
tag : todo
md5 : 3057d15df845cc990e2f01ec72b8cf0a

        # [todo] - Don't just check for blank password but invalid as well
        # Poor mans username/password grabbing
        print BOLD + "Username: " + RESET
        _username = $stdin.gets.chomp
        if _username.empty?
            Printer.print_status "x", RED
            print BOLD + "Input blank. Please enter your username!\n\n" + RESET
            return false
        end
            print "\n"
            # Get repo information, if blank give error
        Printer.print_status "!", YELLOW 
        print BOLD + "Repo information required\n" + RESET
        print "      Please provide owner that repo is under followed by repo name\n"
        print "      e.g. owner: nhmood, repo: watson (case sensitive)\n"

Wrap Bitbucket password grabbing into separate method [lib/watson/bitbucket.rb]

filename : lib/watson/bitbucket.rb
line # : 14
tag : todo
md5 : 89f9f53b636eaeccfe1b003aefd5d271

# [todo] - Wrap Bitbucket password grabbing into separate method
    # Include for debug_print
include Watson
    #############################################################################   
# Setup remote access to Bitbucket
# Get Username, Repo, and PW and perform necessary HTTP calls to check validity
def setup(config)

    # Identify method entry
    debug_print "#{ self.class } : #{ __method__ }\n"

    Printer.print_status "+", GREEN
    print BOLD +  "Attempting to access Bitbucket...\n" + RESET

    # Check config to make sure no previous repo info exists

Properly scope Printer class so we dont need the Printer. for [lib/watson/github.rb]

filename : lib/watson/github.rb
line # : 14
tag : review
md5 : 5e268391308470516f3cfc652eb78509

    # [review] - Properly scope Printer class so we dont need the Printer. for 
    #            method calls?
    # [todo] - Keep asking for user data until valid instead of leaving app
            # Include for debug_print
    include Watson

    #############################################################################   
    # Setup remote access to GitHub 
    # Get Username, Repo, and PW and perform necessary HTTP calls to check validity
    def setup(config)
            # Identify method entry
        debug_print "#{ self.class } : #{ __method__ }\n"

        Printer.print_status "+", GREEN

If input msg is a Hash, use pp to dump it [lib/watson.rb]

filename : lib/watson.rb
line # : 46
tag : todo
md5 : 86ace81eb3985d24953abc266e49dcdb

# [todo] - If input msg is a Hash, use pp to dump it
        # Print only if DEBUG flag of calling class is true OR 
    # GLOBAL_DEBUG_ON of Watson module (defined above) is true
    # AND GLOBAL_DEBUG_OFF of Watson module (Defined above) is false
        # Sometimes we call debug_print from a static method (class << self)
    # and other times from a class method, and ::DEBUG is accessed differently 
    # from a class vs object, so lets take care of that
    _DEBUG = (self.is_a? Class) ? self::DEBUG : self.class::DEBUG
        print "=> #{msg}" if ( (_DEBUG == true || GLOBAL_DEBUG_ON == true) && (GLOBAL_DEBUG_OFF == false))
end 
        ###########################################################
# Perform system check to see if we are able to use unix less for printing 

Not sure if explicit file close is required here [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 239
tag : review
md5 : ae184abbc1e4155a7575a3adb8c2c1b8

        # [review] - Not sure if explicit file close is required here
        _rc = File.open(@rc_file, 'r').read

        debug_print "\n\n"  

        # Create temp section var to keep track of what we are populating in config
        _section = ""

        # Keep index to print what line we are on
        # Could fool around with Enumerable + each_with_index but oh well
        _i = 0;
            # Fix line endings so we can support Windows/Linux edited rc files
        _rc.gsub!(/\r\n?/, "\n")
        _rc.each_line do | _line |
            debug_print "#{ _i }: #{ _line }" if (_line != "\n")
            _i = _i + 1

gsub uses (.?)+ to grab anything after lib (optional), better regex? [lib/watson/config.rb]

filename : lib/watson/config.rb
line # : 178
tag : review
md5 : 93235816f8f628bd2b66ab6a860292dc

        # [review] - gsub uses (.?)+ to grab anything after lib (optional), better regex? 
        _full_path = __dir__.gsub(/\/lib(.?)+/, '') + "/" + "assets/defaultConf"
        debug_print "Full path to defaultConf (in gem): #{ _full_path }\n"

        # Check to make sure we can access the default file
        if !Watson::FS.check_file(_full_path)
            print "Unable to open #{ _full_path }\n"
            print "Cannot create default, exiting...\n"
            return false
        else
            # Open default config file in read mode and read into temp
            _input = File.open(_full_path, 'r')
            _default = _input.read
                # Open rc file in current directory in write mode and write default
            _output = File.open(@rc_file, 'w')
            _output.write(_default)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.