| 22 | |
| 23 | |
| 24 | class RockStar: |
| 25 | |
| 26 | def __init__(self, days=400, days_off=(), file_name=DEFAULT_FILE_NAME, |
| 27 | code=HELLO_WORLD_CPP, off_fraction=0.0): |
| 28 | self.repo = None |
| 29 | self.days = days |
| 30 | self.file_name = file_name |
| 31 | self.file_path = os.path.join(os.getcwd(), file_name) |
| 32 | self.code = code |
| 33 | self.repo_path = os.getcwd() |
| 34 | self.messages_file_name = 'commit-messages.json' |
| 35 | self.messages_file_path = os.path.join(os.path.dirname( |
| 36 | os.path.abspath(__file__)), self.messages_file_name) |
| 37 | self.days_off = list(map(str.capitalize, days_off)) |
| 38 | self.off_fraction = off_fraction |
| 39 | |
| 40 | self._load_commit_messages() |
| 41 | |
| 42 | def _load_commit_messages(self): |
| 43 | with open(self.messages_file_path) as f: |
| 44 | messages_file_contents = json.load(f) |
| 45 | names = messages_file_contents['names'] |
| 46 | messages = messages_file_contents['messages'] |
| 47 | self.commit_messages = [m.format(name=choice(names)) for m in messages] |
| 48 | |
| 49 | def _get_random_commit_message(self): |
| 50 | return choice(self.commit_messages) |
| 51 | |
| 52 | def _make_last_commit(self): |
| 53 | with open(self.file_path, 'w') as f: |
| 54 | f.write(self.code) |
| 55 | |
| 56 | os.environ['GIT_AUTHOR_DATE'] = '' |
| 57 | os.environ['GIT_COMMITTER_DATE'] = '' |
| 58 | self.repo.index.add([self.file_path]) |
| 59 | self.repo.index.commit('Final commit :sunglasses:') |
| 60 | |
| 61 | def _edit_and_commit(self, message, commit_date): |
| 62 | with open(self.file_path, 'w') as f: |
| 63 | f.write(message) |
| 64 | self.repo.index.add([self.file_path]) |
| 65 | date_in_iso = commit_date.strftime("%Y-%m-%d %H:%M:%S") |
| 66 | os.environ['GIT_AUTHOR_DATE'] = date_in_iso |
| 67 | os.environ['GIT_COMMITTER_DATE'] = date_in_iso |
| 68 | self.repo.index.commit(self._get_random_commit_message()) |
| 69 | |
| 70 | @staticmethod |
| 71 | def _get_random_time(): |
| 72 | return time(hour=randint(0, 23), minute=randint(0, 59), |
| 73 | second=randint(0, 59), microsecond=randint(0, 999999)) |
| 74 | |
| 75 | def _get_dates_list(self): |
| 76 | def dates(): |
| 77 | today = date.today() |
| 78 | for day_delta in range(self.days): |
| 79 | day = today - timedelta(days=day_delta) |
| 80 | if day.strftime('%A') in self.days_off: |
| 81 | continue |
no outgoing calls
no test coverage detected