Enforce code pushes

Ryan Reese May 22, 2023

I'm the manager of a group of front end developers at Finalsite. We try to encourage our developers to push once daily, but it's never been something we've been able to enforce. Is there any tool that would allow me as a manager to ensure my developers are pushing the code on their projects? Right now, my only option is to go through the bitbucket projects of all my developers and see if code is pushed at the EOB. It's not realistic due to timezones and chasing down the individual projects my team works on. What can I do?

2 answers

0 votes
Ryan Reese May 30, 2023

I was able to use chatgpt to get majority of the program coded - thank you for offering your help. Here is my new thread with my current problem https://community.atlassian.com/t5/Bitbucket-questions/Bitbucket-REST-API-Rate-Limiting/qaq-p/737597

0 votes
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 22, 2023

Although I don't understand the use case (enforcing a push even if someone hasn't created anything that could form a real commit is not a good practice), I think it can be automated with some scripting.

You could use the Bitbucket Cloud REST API to get the latest commits per repository. You could, of course, iterate over all projects and all repositories.

You could even email the owner of a fork if he/she hasn't pushed anything...

Ryan Reese May 22, 2023

We have had recent issues with developers taking unplanned PTO or any number of reasons to where anyone else who needs to go into the project cannot access the most up to date code in the repository. 

 

There may be very little that needs pushed on a daily basis, but we have developers who potentially go weeks without code pushes, and if that employee no longer works for us (for whatever reason), it then puts us in a bind. I'm trying to remedy the problem of irretrievable code. This API sounds intriguing .Thank you.

Like Aron Gombas _Midori_ likes this
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 22, 2023

I see. I'm sure you can roll out an automatic solution for this using the REST API, and it shouldn't take longer than a few hours - few days.

Ryan Reese May 23, 2023

Question for you: all of our projects are repositories within 1 workspace. Is there a way to ignore the {repo_slug} so all recent commits in the workspace are there? Or perhaps find all recent commits by X user? I'm looking to possibly create some sort of report to where I can see the last time any X user committed to repositories.

Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 23, 2023

In a somewhat similar use case, we implemented a script both for GitHub (Cloud) and I think for Bitbucket Cloud where we were:

  • iterating through the repositories
  • iterating through all active branches in the repo
  • get its head (latest commit)

And used that commit as the "most recent" one.

Which means that there was no REST API end-point that returned this info "ready-made".

(*) If you're interested I can try to find the code (I think it was written in Javascript and is being executed as a Google script, but my memories may be wrong).

Like Ryan Reese likes this
Ryan Reese May 24, 2023

That'd be fantastic! Can you please do that? No worries if you can't, but that's at least a roadmap for me to develop it.

Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 24, 2023

I checked and it turns out our code is written for GitHub only, not for Bitbucket. So you won't be able to use it as is.

It may be useful to illustrate the idea though...

Interested?

Ryan Reese May 25, 2023

Yeah, that can't hurt. Yes please.

Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 26, 2023

Here is the core part that works with the GitHub API, collects all repos, all branches per repo, and the latest commit on the branch.

If you want to see the iteration logic, I can also show that, but I would have to remove confidential details...

The formatting gets broken because of this site's formatter, sorry.

var SourceCodeBackupChecker = (function() {
// ... code omitted ...

function getRepos() {
var url = "https://api.github.com/user/repos";
var options = {
"method": "get",
"headers" : { "Authorization": Config.getGitHubBasicAuthHeaderValue() }
};
var response = UrlFetchApp.fetch(url, options);
return JSON.parse(response.getContentText());
}

function getBranches(repoName) {
var items = [];
var pageSize = 100; // maximum allowed by the endpoint
var maxResults = 1000; // safe limit
for (var i = 1; i < (maxResults / pageSize); i++) {
var url = "https://api.github.com/repos/arongombas/" + repoName + "/branches?" + Utils.toUrlParams({
"page": i,
"per_page": pageSize
});
var options = {
"method": "get",
"headers" : { "Authorization": Config.getGitHubBasicAuthHeaderValue() }
};
var response = UrlFetchApp.fetch(url, options);
var newItems = JSON.parse(response.getContentText());
items = items.concat(newItems);
if (!newItems || (newItems.length < pageSize)) {
break;
}
}
return items;
}

function getCommit(url) {
var options = {
"method": "get",
"headers" : { "Authorization": Config.getGitHubBasicAuthHeaderValue() }
};
var response = UrlFetchApp.fetch(url, options);
return JSON.parse(response.getContentText());
}

return {
"checkSourceCodeBackup": checkSourceCodeBackup
};
})();


 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events