Module: PWN::Plugins::Git

Defined in:
lib/pwn/plugins/git.rb

Overview

Used primarily in the past to clone local repos and generate an html diff to be sent via email (deprecated). In the future this plugin may be used to expand upon capabilities required w/ Git.

Constant Summary collapse

@@logger =
PWN::Plugins::PWNLogger.create

Class Method Summary collapse

Class Method Details

.authorsObject

Author(s)

Jacob Hoopes [email protected]



126
127
128
129
130
# File 'lib/pwn/plugins/git.rb', line 126

public_class_method def self.authors
  "AUTHOR(S):
    Jacob Hoopes <[email protected]>
  "
end

.dump_all_repo_branches(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Plugins::Git.dump_all_repo_branches( git_url: 'required git repo url' )



69
70
71
72
73
74
# File 'lib/pwn/plugins/git.rb', line 69

public_class_method def self.dump_all_repo_branches(opts = {})
  git_url = opts[:git_url].to_s.scrub
  `git ls-remote #{git_url} 2> /dev/null`.to_s.scrub
rescue StandardError => e
  raise e
end

.gen_html_diff(opts = {}) ⇒ Object

Supported Method Parameters

PWN::Plugins::Git.gen_html_diff( repo: 'required git repo name', branch: 'required git repo branch (e.g. master, develop, etc)', since: 'optional date, otherwise default to last pull' )



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pwn/plugins/git.rb', line 19

public_class_method def self.gen_html_diff(opts = {})
  git_repo_name = opts[:repo].to_s
  git_repo_branch = opts[:branch].to_s
  since_date = opts[:since]

  git_pull_output = '<div style="background-color:#CCCCCC; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">'
  if since_date
    git_pull_output << "<h3>#{git_repo_name}->#{git_repo_branch} Diff Summary Since #{since_date}</h3>"
    git_entity = `git log --since #{since_date} --stat-width=65535 --graph`.to_s.scrub
  else
    git_pull_output << "<h3>#{git_repo_name}->#{git_repo_branch} Diff Summary Since Last Pull</h3>"
    git_entity = `git log ORIG_HEAD.. --stat-width=65535 --graph 2> /dev/null`.to_s.scrub
  end
  # For debugging purposes
  @@logger.info(git_entity)
  git_pull_output << git_entity.gsub("\n", '<br />')
  git_pull_output << '</div>'
  git_pull_output << '<br />'

  git_pull_output
rescue StandardError => e
  raise e
end

.get_author(opts = {}) ⇒ Object

Supported Method Parameters

get_author( repo_root: dir_path, from_line: line_no, to_line:line_no, target_file: entry, entry_beautified: entry_beautified )



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/pwn/plugins/git.rb', line 85

public_class_method def self.get_author(opts = {})
  repo_root = opts[:repo_root]
  from_line = opts[:from_line]
  to_line = opts[:to_line]
  target_file = opts[:target_file]
  entry_beautified = opts[:entry_beautified]

  # In order to get the original author
  # we need to query the original file
  # instead of the .JS-BEAUTIFIED file
  if entry_beautified
    target_file.gsub!(/\.JS-BEAUTIFIED$/, '')
    target_file_line_length = `wc -l #{target_file}`.split.first.to_i
    target_file_line_length = 1 if target_file_line_length < 1 # wc -l doesn't count line is \n is missing

    author = (
      repo_root: repo_root,
      from_line: 1,
      to_line: target_file_line_length,
      target_file: target_file
    )
  else
    if from_line.to_i && to_line.to_i < 1
      from_line = 1
      to_line = 1
    end
    author = (
      repo_root: repo_root,
      from_line: from_line,
      to_line: to_line,
      target_file: target_file
    )
  end

  author ||= 'N/A'
rescue StandardError => e
  raise e
end

.helpObject

Display Usage for this Module



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/pwn/plugins/git.rb', line 134

public_class_method def self.help
  puts "USAGE:
    # Run gen html diff and return its result
    #{self}.gen_html_diff(
      repo: 'required - required git repo name',
      branch: 'required - required git repo branch (e.g. master, develop, etc)',
      since: 'optional - optional date, otherwise default to last pull'
    )

    # Run dump all repo branches and return its result
    #{self}.dump_all_repo_branches(
      git_url: 'required - required git repo url'
    )

    # Run get author and return its result
    #{self}.get_author(
      repo_root: 'optional - repo root value consumed by #get_author',
      from_line: 'optional - from line value consumed by #get_author',
      to_line: 'optional - to line value consumed by #get_author',
      target_file: 'optional - target file value consumed by #get_author',
      entry_beautified: 'optional - entry beautified value consumed by #get_author'
    )

    # Print the AUTHOR(S) string for this module.
    #{self}.authors
  "
  constants.sort
end