Module: Canvas::Workflow::Travis

Defined in:
lib/canvas/workflow/travis.rb

Class Method Summary collapse

Class Method Details

.created?(file) ⇒ Boolean

Note:

Behavior is undefined if the reason that there is no previous successful build is because it was struck from the git history. If this is the case, then there is no reliable way to determine which files have been changed without brute-force checking every file against the Canvas site.

Has file been created since the last successful build?

Parameters:

  • file (String)

    a file name

Returns:

  • (Boolean)

    true if the file has been created since the last successful build.

Raises:

  • (Error)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/canvas/workflow/travis.rb', line 53

def self.created?(file)
  if commit_sha.nil?
    # get the list of all files on this branch being tracked by git
    @created ||= `git ls-tree -r #{branch} --name-only`
  else
    # get the list of files that have been created since the last passed
    # commit
    @created ||= `git diff --diff-filter=AR --name-only #{commit_sha}`
  end
  raise Error.new($?.exitstatus) if $?.exitstatus != 0

  # check if the param file has been created
  @created.include?(file)
end

.modified?(file) ⇒ Boolean

Note:

Behavior is undefined if the reason that there is no previous successful build is because it was struck from the git history. If this is the case, then there is no reliable way to determine which files have been changed without brute-force checking every file against the Canvas site.

Has file been modified since the last successful build?

Parameters:

  • file (String)

    a file name

Returns:

  • (Boolean)

    true if the file has been modified since the last successful build.

Raises:

  • (Error)


77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/canvas/workflow/travis.rb', line 77

def self.modified?(file)
  if commit_sha.nil?
    # get the list of all files on this branch being tracked by git
    @modified ||= `git ls-tree -r #{branch} --name-only`
  else
    # get the list of files that have been modified since the last
    # passed commit
    @modified ||= `git diff --diff-filter=M --name-only #{commit_sha}`
  end
  raise Error.new($?.exitstatus) if $?.exitstatus != 0

  # check if the param file has been modified
  @modified.include?(file)
end

.removed?(file) ⇒ Boolean

Has file been removed since the last successful build?

Parameters:

  • file (String)

    a file name

Returns:

  • (Boolean)

    true if the file has been removed since the last successful build.

Known bugs:

  • The orignal paths of those files that have been renamed will not be identified as having been removed.

  • This will not recursively identify empty directories.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/canvas/workflow/travis.rb', line 29

def self.removed?(file)
  if commit_sha.nil?
    # no files have been removed, since there is no previous successful
    # build on this branch
  else
    # get the list of files that have been deleted since the last passed
    # commit
    @removed ||= `git diff --diff-filter=D --name-only #{commit_sha}`
    raise Error.new($?.exitstatus) if $?.exitstatus != 0
  end

  # check if the param file has been removed
  @removed.include?(file)
end