Skip to content

Commit

Permalink
pre-hook
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshaNalluru committed Mar 1, 2024
1 parent babc232 commit c539c73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
39 changes: 17 additions & 22 deletions common/git-hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,22 @@

const { execSync } = require("child_process");

function getRemoteName() {
function preparePrePushRemote() {
try {
const remoteName = execSync(`git rev-parse --abbrev-ref --symbolic-full-name @{u}`, {
encoding: "utf-8",
stdio: ["pipe", "pipe", "pipe"],
})
.toString()
.trim()
.split("/");
return remoteName[0];
execSync("git remote add prepush https://github.com/Azure/azure-sdk-for-js.git");
} catch (e) {
return "";
console.log("Remote 'prepush' already exists. No need to add it again. Continuing...");
}
execSync("git fetch prepush");
}

function getLocalCommitsNotMerged() {
// Fetch updates from the remote repository
execSync("git fetch");

const remoteName = getRemoteName();
if (remoteName == "") return [];
preparePrePushRemote();

// Get the list of commits not merged to the remote main branch
const localCommitsNotMerged = execSync(`git log ${remoteName}/main..HEAD --oneline`)
const localCommitsNotMerged = execSync(`git log prepush/main..HEAD --oneline`)
.toString()
.trim()
.split("\n");
Expand Down Expand Up @@ -90,12 +82,15 @@ function executeScript(projectFolderPath, script) {
async function execute(listOfModifiedProjects, check_script, fix_script) {
const errors = [];
listOfModifiedProjects.forEach((projectFolderPath) => {
const error = executeScript(projectFolderPath, check_script);
if (error !== "") {
errors.push({
project: projectFolderPath,
err: error,
});
if (projectFolderPath && projectFolderPath.trim() != "") {
console.log(`Checking the format for the project: ${projectFolderPath}`);
const error = executeScript(projectFolderPath, check_script);
if (error !== "") {
errors.push({
project: projectFolderPath,
err: error,
});
}
}
});

Expand All @@ -122,7 +117,7 @@ async function execute(listOfModifiedProjects, check_script, fix_script) {
return false;
}

console.log("About to Push the code to Github\n");
console.log("Preparing the pre-push script....\n");

async function main() {
const localCommits = getLocalCommitsNotMerged();
Expand All @@ -137,4 +132,4 @@ async function main() {
}
}

// main();
main();
5 changes: 1 addition & 4 deletions sdk/storage/storage-blob/test/utils/testutils.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { TokenCredential, GetTokenOptions, AccessToken } from "@azure/core-auth"
import { isPlaybackMode, Recorder, RecorderStartOptions } from "@azure-tools/test-recorder";
import { StorageClient } from "../../src/StorageClient";
import { Pipeline } from "@azure/core-rest-pipeline";
import {
FindReplaceSanitizer,
RegexSanitizer,
} from "@azure-tools/test-recorder";
import { FindReplaceSanitizer, RegexSanitizer } from "@azure-tools/test-recorder";

export const testPollerProperties = {
intervalInMs: isPlaybackMode() ? 0 : undefined,
Expand Down

0 comments on commit c539c73

Please sign in to comment.